作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
非常感谢对此的帮助:我无法使用 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/
我是一名优秀的程序员,十分优秀!