【发布时间】:2019-03-06 13:18:55
【问题描述】:
我想为 iOS 和 Android 创建 react-native 模块并在应用程序中使用它。
我想像本地模块一样使用它,而不是上传到 npm。
当我按照官方文档中描述的步骤操作时,我总是在将模块导入 App.js 文件时遇到这些错误:
从 'react-test-module' 导入 MyModule;
找不到模块“react-test-module”的声明文件。 '/Users/dbellerose/Path/to/My/Module/react-test-module/index.js' 隐含了一个 'any' 类型。
如果存在,请尝试npm install @types/react-test-modulet,或者添加一个包含 `declare module 'react-test-module' 的新声明 (.d.ts) 文件;
当我运行 iOS 应用程序时:
无法从 /Users/Path/To/My/App/App.js 解析模块 react-test-module:模块 react-test-module 在 Haste 模块映射中不存在。
该消息给了我一些解决问题的提示,但它不起作用。
要解决,请尝试以下操作:
1.清除守望者手表:watchman watch-del-all。
2、删除node_modules文件夹:rm -rf node_modules && npm install。
3. 重置 Metro Bundler 缓存:rm -rf /tmp/metro-bundler-cache-* 或 npm start -- --reset-cache。
4. 移除急速缓存:rm -rf /tmp/haste-map-react-native-packager-*.
那么你知道什么是创建模块并在应用程序中使用它而不将包上传到 npm 的好过程吗?
最好的问候,
大卫
【问题讨论】:
-
你应该在你的模块文件中写下精确的方向
-
^^ 正如 nerius 所说,您需要使用
./some_path/module/component.ts之类的目录链接到该文件 - 如果您想使用像 '@test_modules/test.module.ts` 这样的别名,那么告诉我,我会为你解答。 -
您好,component.ts 文件是什么?我的模块中没有它
标签: ios reactjs react-native module