gpt4 book ai didi

webpack - 找不到模块 : Error: Cannot resolve module 'react' when I use webpack

转载 作者:行者123 更新时间:2023-12-03 13:39:32 25 4
gpt4 key购买 nike

非常感谢对此的帮助:我无法使用 webpack 进行构建,我得到了一个简短的错误列表,开头为:

Module not found: Error: Cannot resolve module 'react' in ../client/front_desk.jsx

最后得到一个长列表,如下所示:

Module not found: Error: Cannot resolve 'file' or 'directory' ../node_modules/process/browser.js

这是我的 webpack.config.js:

const webpack = require('webpack');
const commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js');

module.exports = {
entry: {
front_desk: './front/client/front_desk',
},
resolve: {
extensions: ['.js', '.jsx'],
},
output: {
path: 'front/public/js',
filename: '[name].js', // Template based on keys in entry above
},
module: {
loaders: [
{
test: /\.(jsx|js)?$/,
loader: 'babel',
query: {
presets: ['es2015', 'react'],
},
},
],
},
plugins: [commonsPlugin],
};

还有我的 .babelrc:

{
"plugins": ["syntax-jsx"],
"presets": ["react", "es2015"],
}

我的依赖项列表在 package.json 中:

  "dependencies": {
"aguid": "*",
"babel-plugin-syntax-jsx": "*",
"babel-preset-es2015": "*",
"babel-preset-react": "*",
"babel-register": "*",
"bcrypt": "*",
"eslint": "*",
"eslint-config-airbnb": "^8.0.0",
"eslint-plugin-import": "^1.6.1",
"eslint-plugin-jsx-a11y": "^1.0.4",
"eslint-plugin-react": "^5.0.1",
"hapi": "*",
"hapi-react-views": "^7.0.0",
"inert": "*",
"isomorphic-fetch": "*",
"mailparser": "*",
"mandrill-api": "*",
"mongodb": "*",
"nodemon": "*",
"react": "^15.0.2",
"react-dom": "^15.0.2",
"react-redux": "*",
"redux": "*",
"redux-thunk": "*",
"twilio": "*",
"vision": "*",
"webpack-dev-server": "^1.14.1"
},
"devDependencies": {
"babel-core": "*",
"babel-loader": "*",
"faucet": "*",
"jsx-loader": "^0.13.2",
"nodemon": "*",
"tape": "*",
"webpack": "*"
}

最佳答案

想通了!我首先使用 --display-error-details 运行 webpack,在我看来,默认情况下它应该一直处于打开状态。 webpack --progress --color --watch --display-error-details

这告诉我,webpack 遇到如此困难的原因是因为我告诉它寻找的扩展有问题:

  resolve: {
extensions: ['.js', '.jsx'],
},

会寻找react.js.js和react.js.jsx,而不仅仅是react.js。所以,我必须将其更新为:

  resolve: {
extensions: ['', '.js', '.jsx'],
},

这解决了它! =)

关于webpack - 找不到模块 : Error: Cannot resolve module 'react' when I use webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37015447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com