捆绑失败:错误:解决模块`metro / src / lib / bundle-modules / HMRClient`时

时间:2019-05-17 12:45:56

标签: react-native

我创建了一个名为Metro的新项目。当我运行它时,此错误出现在我的cli nodejs上:

错误:绑定失败:错误:解决模块metro/src/lib/bundle-modules/HMRClient时,发现急速程序包metro。但是,在软件包中找不到模块src/lib/bundle-modules/HMRClient。实际上,这些文件都不存在:

  • D:\programming\react native\metro\src\lib\bundle-modules\HMRClient(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
  • D:\programming\react native\metro\src\lib\bundle-modules\HMRClient\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
    • at resolveHasteName (D:\programming\react native\metro\node_modules\metro-resolver\src\resolve.js:236:9)
    • at Object.resolve (D:\programming\react native\metro\node_modules\metro-resolver\src\resolve.js:103:20)
    • at ModuleResolver.resolveDependency (D:\programming\react native\metro\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:143:31)
    • at ResolutionRequest.resolveDependency (D:\programming\react native\metro\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
    • at DependencyGraph.resolveDependency (D:\programming\react native\metro\node_modules\metro\src\node-haste\DependencyGraph.js:283:16)
    • at Object.resolve (D:\programming\react native\metro\node_modules\metro\src\lib\transformHelpers.js:261:42)
    • at dependencies.map.result (D:\programming\react native\metro\node_modules\metro\src\DeltaBundler\traverseDependencies.js:399:31)
    • at Array.map (<anonymous>)
    • at resolveDependencies (D:\programming\react native\metro\node_modules\metro\src\DeltaBundler\traverseDependencies.js:396:18)
    • at D:\programming\react native\metro\node_modules\metro\src\DeltaBundler\traverseDependencies.js:269:33

我的本​​机版本是 0.59.8

3 个答案:

答案 0 :(得分:1)

我陷入了同样的问题, 所以我所做的是:

  • 在以下路径找到文件:node_modules/react-native/Libraries/Utilities/HMRClient.js
  • 更改行:const MetroHMRClient = require('metro/src/lib/bundle-modules/HMRClient');
  • 收件人:const MetroHMRClient = require('../../../@react-native-community/cli/node_modules/metro/src/lib/bundle-modules/HMRClient');

对于我唯一有用的是,唯一的问题是,如果重新安装de node_modules,则需要再次替换该行。因此,我将此脚本添加到了package.json中:

"postinstall": "sed -i '' \"s#metro#../../../@react-native-community/cli/node_modules/metro#g\" ./node_modules/react-native/Libraries/Utilities/HMRClient.js"

上面的脚本负责在每次新的npm安装后进行替换

答案 1 :(得分:0)

I had the same issue after updating react-native to v0.59.8.

What I ended up doing was adding a dev dependency to metro package with npm install --save-dev metro which is currently at v0.54.1.

This solved it for me!

答案 2 :(得分:0)

因为我将这个项目命名为Metro,所以出现了问题。我用新名称创建了一个新项目,问题已解决。