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

标签 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

我尝试了所有步骤,但没有任何效果。我也尝试过拖运,但这对我来说并不奏效。

最佳答案

符号链接(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/

相关文章:

react-native - 如何在 react-native 中创建线性渐变(在图像顶部和应用栏下方)

jquery - 在react componentDidMount中bind(this)后获取jquery对象

javascript - React-bootstrap 选项卡 : Warning: In the context of a `<TabContainer>` , `<NavItem>` s 被赋予生成的 `id` 和 `aria-controls` 属性

Android独有的闪屏: how to make it fill screen?

ios - react native : SyntaxError: Strict mode does not allow function declarations in a lexically nested statement

reactjs - 如何将react-native-vector-icons与react-native-web一起使用?

javascript - 在react中使用redux形成

reactjs - 在生产中使用react : What must be the size of React in production?

javascript - Realm React Native - 需要迁移 : Target type 'string' doesn't exist for property 'emailAddresses'

react-native - 无法将 react native 线性梯度别名为 react native Web应用程序的 react native 网络线性梯度