我正在尝试使用相对路径中的包,并且我已经完成了 npm install ../../ExamplePackage
和 react-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
我尝试了所有步骤,但没有任何效果。我也尝试过拖运,但这对我来说并不奏效。
最佳答案
符号链接(symbolic link)可能导致您的问题。使用本地路径的 npm install
会在 node_modules
中安装库,并使用指向包本地路径的符号链接(symbolic link)。不幸的是,这会导致 React Native Metro bundler 出现问题(“Haste 模块映射中不存在”)。
我在使用 npm install
时遇到了同样的问题。 react-native install
对我有用,并且不会创建符号链接(symbolic link)。
使用 wml
是另一种好方法。它通过自动复制本地库与其在 node_modules 中安装的副本之间的更改来复制符号链接(symbolic link)的行为。
参见https://github.com/facebook/react-native/issues/23327对于类似的问题。
关于reactjs - 使用react-native安装本地包作为依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49730789/