在我的包 JSON 中将 React 和 React-dom 更改为 16.2.0 并收到以下错误。
Uncaught Error: Cannot find module "react/lib/ReactComponentTreeHook"
已尝试清除我的node_modules,重新安装所有内容,从一个新项目开始并添加小块依赖项以缩小问题范围,并尝试堆栈溢出中已经看到的几乎所有选项。
我的package.json如下:
{
"name": "",
"version": "0.0.1",
"description": "",
"main": "index.js",
"repository": {
"type": "git",
"url": "..."
},
"scripts": {
"dev": "webpack -d --watch",
"build": "webpack -p"
},
"dependencies": {
"axios": "^0.17.1",
"body-parser": "^1.18.2",
"classnames": "^2.2.5",
"connect-mongo": "^2.0.0",
"cookie-parser": "^1.4.3",
"express": "^4.16.2",
"express-session": "^1.15.6",
"moment": "^2.19.3",
"mongoose": "^4.13.6",
"multer": "^1.3.0",
"node-sass": "^4.7.2",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"qs": "^6.5.1",
"react": "^16.2.0",
"react-click-outside": "^3.0.0",
"react-dom": "16.2.0",
"react-redux": "5.0.6",
"redux": "3.7.2",
"redux-logger": "^3.0.6",
"redux-promise-middleware": "^5.0.0",
"redux-thunk": "^2.2.0",
"underscore": "^1.8.3"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"css-loader": "^0.28.7",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.5",
"redux-devtools": "^3.4.1",
"sass-loader": "^6.0.6",
"serve": "^6.4.1",
"style-loader": "^0.19.0",
"svg-sprite-webpack-plugin": "^1.1.0",
"svg-spritemap-webpack-plugin": "^1.0.3",
"url-loader": "^0.6.2",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"webpack": "^3.10.0"
},
"author": "",
"license": "ISC",
"homepage": ""
}
在出错的行上放置断点后,堆栈跟踪似乎来自react-dom的导入,但如果这是匹配react的最新版本,我不明白为什么我有这个问题。
出于我能想到的选择,如果有任何帮助,我将不胜感激。谢谢。
最佳答案
Have tried clearing my node_modules, reinstalling everything
请记住,从 NPM 第 5 版开始,它会生成包锁定文件,如果不清除,重新安装模块将无法正常工作。
还要检查以下内容 - 如果某个包对旧的 react
包版本有自己的依赖项,它将被安装到嵌套的 node_modules
目录中,然后一切都依赖于项目/装载机结构。在这种情况下,将会加载无效的新版或旧版软件包。在某些 npm 包中,例如 graphql
,针对这种情况添加了特殊警告:“也许您安装了不同版本的包”。
所以,检查其他软件包的版本,也许更新它们。
关于javascript - 更新到 React 16.2.0 时找不到模块 "react/lib/ReactComponentTreeHook"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47640220/