Module not found: Error: Cannot resolve module 'react' when I use webpack
Module not found: Error: Cannot resolve module 'react' when I use webpack
非常感谢在这方面的帮助:
我无法使用 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 进行构建,我得到了一个简短的错误列表,开头为:
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'],
},
哪个修好了! =)