我当时正在使用react@15.6.2但是正在尝试更新到16.2.0
我删除了node_modules文件夹,然后执行npm cache clean
和npm install
但是,控制台会一直显示此消息
UNMET PEER DEPENDENCY react@15.6.2 invalid
在我运行webpack服务器之后,浏览器只会抛出一条错误消息:
Cannot read property 'ReactCurrentOwner' of undefined
为什么会发生?
这是我的package.json的样子:
"devDependencies": {
"autoprefixer": "^6.3.6",
"babel-core": "^6.8.0",
"babel-loader": "^6.2.4",
"babel-plugin-transform-class-properties": "^6.8.0",
"babel-plugin-transform-runtime": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"css-loader": "^0.23.1",
"eslint": "^2.9.0",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-import": "^1.8.0",
"eslint-plugin-jsx-a11y": "^1.2.0",
"eslint-plugin-react": "^5.1.1",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.8.5",
"firebase": "^4.13.0",
"history": "^4.7.2",
"html-webpack-plugin": "^2.16.1",
"install": "^0.11.0",
"less": "^2.7.1",
"less-loader": "^2.2.3",
"open-browser-webpack-plugin": "0.0.2",
"postcss-loader": "^2.1.4",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-icons": "^2.2.7",
"react-route": "^1.0.3",
"react-router-dom": "^4.2.2",
"rimraf": "^2.5.2",
"style-loader": "^0.13.1",
"styled-components": "^3.2.3",
"url-loader": "^0.5.7",
"webpack": "^1.13.0",
"webpack-dev-server": "^1.14.1"
}
答案 0 :(得分:1)
我刚解决了这个问题。
让我感到困扰的是,即使您删除了node_modules文件夹,包版本也保持不变(旧版本)。我仍然不知道为什么
因为react
的错误消息表明:我react-dom
和npm ls react
都卸载了{
npm ERR! peer dep missing: react@^16.0.0, required by react-dom@16.2.0
执行npm install react@16.2.0
和npm install react-dom@16.2.0
重新安装后,浏览器的错误消息消失了! :)