8

我正在尝试使用来自相对路径的包,并且我已经完成了npm install ../../ExamplePackagereact-native install ../../ExamplePackage. 这些包在多个级别上是相对的,而不仅仅是一个级别。

我收到以下错误

error: bundling failed: Error: Unable to resolve module `ExamplePackage` from `/Users/vikasagr/workspace/test/ReactNative/MyPackage/src/index.js`: Module `ExamplePackage` does not exist in the Haste module map

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
  1. Clear watchman watches: `watchman watch-del-all`.
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.
    at ModuleResolver.resolveDependency (/Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:161:1460)
    at ResolutionRequest.resolveDependency (/Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:91:16)
    at DependencyGraph.resolveDependency (/Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/node-haste/DependencyGraph.js:272:4579)
    at dependencies.map.relativePath (/Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/DeltaBundler/traverseDependencies.js:376:19)
    at Array.map (<anonymous>)
    at resolveDependencies (/Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/DeltaBundler/traverseDependencies.js:374:16)
    at /Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/DeltaBundler/traverseDependencies.js:212:33
    at Generator.next (<anonymous>)
    at step (/Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:313)
    at /Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:473

我尝试了所有步骤,但没有任何效果。我也尝试过 haul 但这对我也不起作用。

4

2 回答 2

7

符号链接可能导致您的问题。with a local path使用指向包的本地路径的符号链接npm install安装库。node_modules不幸的是,这会导致 react 本机 Metro 捆绑器出现问题(“Haste 模块映射中不存在”)。

我有同样的问题npm installreact-native install对我有用,并且不会创建符号链接。

使用wml是另一种好方法。它通过自动复制本地库与其在 node_modules 中安装的副本之间的更改来复制符号链接的行为。

有关类似问题,请参阅https://github.com/facebook/react-native/issues/23327 。

于 2019-05-13T21:35:15.500 回答
3

你可以试试WML。 https://www.npmjs.com/package/wml

它能做什么:

用实际有效的东西替换 npm 链接!

它对我有用!

干杯

于 2019-11-21T18:09:05.790 回答