【问题标题】:Unable to Resolve Module in React Native App for linked library无法为链接库解析 React Native App 中的模块
【发布时间】:2020-06-02 12:43:02
【问题描述】:

我有一个问题“无法解析模块”

// 请在发布带有来自 google 的第一个结果的链接的 cmets 之前阅读问题。

这是我收到错误的导入行:

import Interactor from 'react-native-native-orientation-interactor';

我做了什么:

  1. 创建一个 react-native 库
  2. 在库文件夹中运行npm link
  3. 在演示本机应用程序中运行 npm link react-native-native-orientation-interactor
  4. 添加导入语句
  5. 导入时出错。

如果我在导入语句上按 Cmd+B,我可以从 node_modules 文件夹中打开一个文件。我还可以在 node_modules 中看到我的库(作为链接)。

但我没有找到任何适合我的解决方案。

Upd1:我在 package.json 中添加了我的库作为依赖项

  "dependencies": {
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-native-orientation-interactor": "*"
  },

【问题讨论】:

  • 你在用expo吗?
  • @Artem 问题解决了吗?我也在尝试添加我的库,该库本地保存在我的系统上并得到相同的错误。

标签: react-native


【解决方案1】:

1 - 首先你已经在 react-native-native-orientation-interaction 中编写了双原生

2 - 另一件事是,不要手动添加依赖项.. 使用正确的安装指南,如

npm install --save react-native-orientation-interactor 要么 yarn add react-native-orientation-interactor

然后链接依赖。

3 - 实际上我没有得到任何名为“react-native-orientation-interaction”的模块。

react-native-orientation

这里是有效的模块依赖之一。 始终阅读整个正确的文档。(如果我错了,请纠正我)

【讨论】:

  • 嗨,谢谢你的回答,真的有双重原生)我的错误,但库和演示应用程序是本地项目,我还没有将库发布到 npm 中。所以我不能通过 npm install 安装依赖项
【解决方案2】:

如果您能够正确链接您的包,并且问题仍然存在。

From my experience you can do two things to resolve error.
1) Try to install pod in ios/ directory
or
2) Just close the Termianl and re-run

【讨论】:

    猜你喜欢
    • 2017-10-11
    • 2016-03-23
    • 1970-01-01
    • 1970-01-01
    • 2018-11-18
    • 1970-01-01
    • 2020-04-15
    • 2020-03-02
    • 2016-12-27
    相关资源
    最近更新 更多