我如何以理智的方式管理反应和其他包?
How do I manage react and other packages in a sane way?
背景
我试图让我的 AirBnB linting 正常工作,并决定卸载我的 npm 包以便全新安装我的 package.json
文件。
我做了什么
我运行 bash 命令:
npm uninstall `ls -1 node_modules | tr '/\n' ' '`
之后,我按照代码库的标准安装程序进行操作,只是将 NPM 安装在正确的目录中。我很确定我做对了。
意外发生的事情
当 运行设置我的 Webpack 时 npm start
一切正常,直到出现以下错误:
to be executed: nodemon --exec babel-node bin/server --no_debug
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `babel-node bin/server --no_debug`
app:config Creating default configuration. +0ms
app:config Looking for environment overrides for NODE_ENV "development". +105ms
app:config Found overrides, applying to default configuration. +6ms
app:webpack:config Create configuration. +727ms
app:webpack:config Enable plugins for live development (HMR, NoErrors). +1ms
app:server:webpack-dev Enable webpack dev middleware. +385ms
app:server:webpack-hmr Enable Webpack Hot Module Replacement (HMR). +38ms
app:bin:server Server is now running at http://172.20.10.2:3000. +9ms
app:bin:server Server accessible via localhost:3000 if you are using the project defaults. +0ms
webpack built b6bb9c1f12e4a68bce6a in 9735ms
Hash: b6bb9c1f12e4a68bce6a
Version: webpack 1.13.3
Time: 9735ms
Asset Size Chunks Chunk Names
app.b6bb9c1f12e4a68bce6a.js 1.9 MB 0 app
vendor.b6bb9c1f12e4a68bce6a.js 664 kB 1 vendor
app.b6bb9c1f12e4a68bce6a.js.map 2.23 MB 0 app
vendor.b6bb9c1f12e4a68bce6a.js.map 808 kB 1 vendor
ERROR in ./~/react-dom/lib/ReactDOMUnknownPropertyHook.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/ReactDOMUnknownPropertyHook.js 15:29-72
ERROR in ./~/react-dom/lib/ReactDOMNullInputValuePropHook.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/ReactDOMNullInputValuePropHook.js 13:29-72
ERROR in ./~/react-dom/lib/ReactDOMInvalidARIAHook.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/ReactDOMInvalidARIAHook.js 14:29-72
ERROR in ./~/react-dom/lib/ReactDebugTool.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/ReactDebugTool.js 16:29-72
ERROR in ./~/react-dom/lib/ReactChildReconciler.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/ReactChildReconciler.js 29:27-70 37:31-74
ERROR in ./~/react-dom/lib/flattenChildren.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/flattenChildren.js 26:27-70 42:33-76
ERROR in ./~/react-dom/lib/checkReactTypeSpec.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/checkReactTypeSpec.js 29:27-70 71:37-80
webpack: bundle is now VALID.
这似乎与 react 版本有关,但我很难相信,因为我没有更改我的 package.json
文件中的任何内容。
相关部分供参考:
"dependencies": {
[...]
"react": "15.0.1",
"react-dom": "^15.0.0",
"react-redux": "^4.0.0",
"react-router": "^2.2.0",
"react-router-redux": "^4.0.0",
我该如何解决这个问题?
考虑使用 yarn 作为 NPM 的替代方案。 Yarn 通过创建 yarn.lock 文件提供确定性安装,这确保在不同时间安装在不同机器上的 dep 都解析为相同版本,类似于 npm install --save-exact foo
.
运行 yarn
(shorthand for yarn install
)等同于rm -rf node_modules && npm install
,这是解决npm问题的第一步,如@Yan马莱克西建议。
Yarn 也将以不同于 npm 的方式表示安装冲突,这可能更容易看出哪个依赖项有问题。在您的情况下,搜索“无法解析模块 'react/lib/ReactComponentTreeHook' 表明 react-hot-loader 可能是一个问题,但如果不查看整个依赖项列表和相关的安装错误就很难判断。
背景
我试图让我的 AirBnB linting 正常工作,并决定卸载我的 npm 包以便全新安装我的 package.json
文件。
我做了什么
我运行 bash 命令:
npm uninstall `ls -1 node_modules | tr '/\n' ' '`
之后,我按照代码库的标准安装程序进行操作,只是将 NPM 安装在正确的目录中。我很确定我做对了。
意外发生的事情
当 运行设置我的 Webpack 时 npm start
一切正常,直到出现以下错误:
to be executed: nodemon --exec babel-node bin/server --no_debug
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `babel-node bin/server --no_debug`
app:config Creating default configuration. +0ms
app:config Looking for environment overrides for NODE_ENV "development". +105ms
app:config Found overrides, applying to default configuration. +6ms
app:webpack:config Create configuration. +727ms
app:webpack:config Enable plugins for live development (HMR, NoErrors). +1ms
app:server:webpack-dev Enable webpack dev middleware. +385ms
app:server:webpack-hmr Enable Webpack Hot Module Replacement (HMR). +38ms
app:bin:server Server is now running at http://172.20.10.2:3000. +9ms
app:bin:server Server accessible via localhost:3000 if you are using the project defaults. +0ms
webpack built b6bb9c1f12e4a68bce6a in 9735ms
Hash: b6bb9c1f12e4a68bce6a
Version: webpack 1.13.3
Time: 9735ms
Asset Size Chunks Chunk Names
app.b6bb9c1f12e4a68bce6a.js 1.9 MB 0 app
vendor.b6bb9c1f12e4a68bce6a.js 664 kB 1 vendor
app.b6bb9c1f12e4a68bce6a.js.map 2.23 MB 0 app
vendor.b6bb9c1f12e4a68bce6a.js.map 808 kB 1 vendor
ERROR in ./~/react-dom/lib/ReactDOMUnknownPropertyHook.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/ReactDOMUnknownPropertyHook.js 15:29-72
ERROR in ./~/react-dom/lib/ReactDOMNullInputValuePropHook.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/ReactDOMNullInputValuePropHook.js 13:29-72
ERROR in ./~/react-dom/lib/ReactDOMInvalidARIAHook.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/ReactDOMInvalidARIAHook.js 14:29-72
ERROR in ./~/react-dom/lib/ReactDebugTool.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/ReactDebugTool.js 16:29-72
ERROR in ./~/react-dom/lib/ReactChildReconciler.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/ReactChildReconciler.js 29:27-70 37:31-74
ERROR in ./~/react-dom/lib/flattenChildren.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/flattenChildren.js 26:27-70 42:33-76
ERROR in ./~/react-dom/lib/checkReactTypeSpec.js
Module not found: Error: Cannot resolve module 'react/lib/ReactComponentTreeHook' in /Users/pedrofigueiredo/Documents/hs/src/healthsite/react/frontend/node_modules/react-dom/lib
@ ./~/react-dom/lib/checkReactTypeSpec.js 29:27-70 71:37-80
webpack: bundle is now VALID.
这似乎与 react 版本有关,但我很难相信,因为我没有更改我的 package.json
文件中的任何内容。
相关部分供参考:
"dependencies": {
[...]
"react": "15.0.1",
"react-dom": "^15.0.0",
"react-redux": "^4.0.0",
"react-router": "^2.2.0",
"react-router-redux": "^4.0.0",
我该如何解决这个问题?
考虑使用 yarn 作为 NPM 的替代方案。 Yarn 通过创建 yarn.lock 文件提供确定性安装,这确保在不同时间安装在不同机器上的 dep 都解析为相同版本,类似于 npm install --save-exact foo
.
运行 yarn
(shorthand for yarn install
)等同于rm -rf node_modules && npm install
,这是解决npm问题的第一步,如@Yan马莱克西建议。
Yarn 也将以不同于 npm 的方式表示安装冲突,这可能更容易看出哪个依赖项有问题。在您的情况下,搜索“无法解析模块 'react/lib/ReactComponentTreeHook' 表明 react-hot-loader 可能是一个问题,但如果不查看整个依赖项列表和相关的安装错误就很难判断。