使用 react-native 安装本地包作为依赖

Vik*_*wal 7 reactjs react-native react-native-web

我想从一个相对路径的使用包和我已经做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
Run Code Online (Sandbox Code Playgroud)

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

gri*_*tis 6

符号链接可能导致您的问题。npm install使用本地路径将库安装在node_modules带有指向包本地路径的符号链接的。不幸的是,这会导致 react native Metro bundler 出现问题(“Haste 模块地图中不存在”)。

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

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

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