如何以理智的方式管理反应和其他包裹?

时间:2016-12-02 13:44:15

标签: node.js reactjs npm webpack create-react-app

背景

我试图让我的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.

它似乎与反应版本有关,但我发现很难相信,因为我在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",

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

考虑使用yarn作为NPM的替代方案。 Yarn通过创建yarn.lock文件来提供确定性安装,该文件可确保在不同时间安装在不同计算机上的deps都解析为相同版本,类似于npm install --save-exact foo

运行yarnyarn install的简写)相当于rm -rf node_modules && npm install,这是解决npm问题的第一步,正如@Yan Maleksi建议的那样。

Yarn也会以不同的方式表示安装冲突,这可能会让您更容易看到哪个依赖项是个问题。在您的情况下,搜索“无法解析模块”react / lib / ReactComponentTreeHook'表明react-hot-loader可能是一个问题,但是如果没有看到整个依赖项列表以及相关的安装错误,很难判断。