未找到模块:错误:无法解析模块';反应';当我使用webpack时
非常感谢您在这方面的帮助: 我无法使用webpack进行构建,我得到一个简短的错误列表,从以下开始:未找到模块:错误:无法解析模块';反应';当我使用webpack时,webpack,babeljs,react-jsx,Webpack,Babeljs,React 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
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],
};
还有我的。巴别塔:
{
"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之所以如此艰难,是因为我告诉它要寻找的扩展出现了问题:
resolve: {
extensions: ['.js', '.jsx'],
},
将查找react.js.js和react.js.jsx,而不仅仅是react.js。因此,我必须将其更新为:
resolve: {
extensions: ['', '.js', '.jsx'],
},
哪一个修好了!=) 隐藏的文档总是通过运气、经验和一些逻辑的混合以及浪费的咖啡来隐藏和探索。谢谢分享!