运行webpack时出现此错误:
Webpack dev build for Rails
Hash: 33fd651f6a6e87a4ef46
Version: webpack 1.15.0
Time: 5619ms
Asset Size Chunks Chunk Names
app-bundle.js 4.09 MB 0 [emitted] app
vendor-bundle.js 1.89 MB 1 [emitted] vendor
[0] multi app 28 bytes {0} [built]
[0] multi vendor 76 bytes {1} [built]
+ 702 hidden modules
ERROR in ../~/react-redux/lib/components/Provider.js
Module not found: Error: Cannot resolve module 'imports' in /Users/matthieu/dev/MyProject/node_modules/react-redux/lib/components
@ ../~/react-redux/lib/components/Provider.js 6:13-29
ERROR in ../~/react-redux/lib/components/connectAdvanced.js
Module not found: Error: Cannot resolve module 'imports' in /Users/matthieu/dev/MyProject/node_modules/react-redux/lib/components
@ ../~/react-redux/lib/components/connectAdvanced.js 17:13-29
我尝试删除node_modules
并再次运行yarn install
。
看来我可能有依赖性问题:
warning "react-redux@5.0.6" has incorrect peer dependency "redux@^2.0.0 || ^3.0.0".
我的package.json
文件如下所示:
# MyProject/package.json
{
"name": "react-webpack-rails-tutorial",
"version": "0.0.1",
"engines": {
"node": "5.10.0",
"npm": "3.5.0"
},
"scripts": {
"postinstall": "cd client && npm install",
"rails-server": "echo 'visit http://localhost:3000/hello_world' && foreman start -f Procfile.dev",
"build:production:client": "(cd client && npm run build:production:client --silent)",
"build:client": "(cd client && npm run build:client --silent",
"build:dev:client": "(cd client && npm run build:dev:client --silent)",
"test": "rspec"
},
"dependencies": {
"react": "^15.4.1",
"react-redux": "^5.0.1",
"redux": "^1.0.0-rc"
}
}
和
# MyProject/client/package.json
{
"name": "react-webpack-rails-tutorial",
"version": "0.0.1",
"engines": {
"node": "5.10.0",
"npm": "3.5.0"
},
"scripts": {
"build:client": "NODE_ENV=production webpack --config webpack.client.rails.config.js",
"build:dev:client": "webpack -w --config webpack.client.rails.config.js",
"build:production:client": "NODE_ENV=production webpack --config webpack.client.rails.build.config.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"autoprefixer": "^6.3.5",
"axios": "^0.9.1",
"babel": "^6.5.2",
"babel-cli": "^6.6.5",
"babel-core": "^6.7.4",
"babel-loader": "^6.2.4",
"babel-runtime": "^6.6.1",
"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"css-loader": "^0.23.1",
"es5-shim": "^4.5.7",
"expose-loader": "^0.7.1",
"imports-loader": "^0.6.5",
"jquery": "^2.2.2",
"jquery-ujs": "^1.2.1",
"loader-utils": "^0.2.13",
"lodash": "^4.7.0",
"react": "^0.14.8 || ^15.0.0",
"react-dom": "^0.14.8 || ^15.0.0",
"react-on-rails": "5.2.0",
"webpack": "^1.15.0"
},
"devDependencies": {
}
}
我该如何解决这个烂摊子?
答案 0 :(得分:0)
您可以尝试以下步骤:
删除node_modules文件夹
将第一个package.json依赖项更改为
"redux": "^2.0.0"
npm i
这应解决您的依赖问题。