gpt4 book ai didi

react-native - 捆绑失败 : Error: While resolving module `metro/src/lib/bundle-modules/HMRClient`

转载 作者:行者123 更新时间:2023-12-05 09:13:25 29 4
gpt4 key购买 nike

我创建了一个名为 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

我的 react-native 版本是 0.59.8

最佳答案

我遇到了同样的问题,所以我所做的是:

  • 在路径中找到文件: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 后进行替换

关于react-native - 捆绑失败 : Error: While resolving module `metro/src/lib/bundle-modules/HMRClient` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56186711/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com