我想为iOS和安卓创建react-native模块,并在应用程序中使用它。
我想像使用本地模块一样使用它,而不是上传到npm。
从‘MyModule -test-module’导入测试模块;
找不到模块'react-test- module‘的声明文件。'/Users/dbellerose/Path/to/My/Module/react-test-module/index.js‘隐式具有“”any“”类型。“如果存在,请尝试使用npm install @types/react-test-modulet,或者添加一个新的声明(.d.ts)文件,其中包含‘`declare’react-test‘;
当我运行iOS应用程序时:
无法从/Users/Path/To/My/App/App.js解析模块react-test-module:Haste模块映射中不存在模块react-test-module。
这条消息给了我一些解决问题的提示,但它不起作用。
要解决此问题,请尝试执行以下操作: 1.清除watchman watches: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.移除haste缓存:rm -rf /tmp/haste-map-react-native-packager-*。
诚挚的问候,
大卫
发布于 2020-03-05 10:48:11
以下是一些步骤,我可以将其作为清单与您分享:
yarn global add create-react-native-modulecreate-react-native-module MyLibrary上运行yarn install
要链接到您的项目,您需要将以下内容添加到您的package.json (路径应该位于您的模块所在的位置)
"react-native-test-module": "file:../",
"react-native-my-library": "file:../../react-native-my-library/"**请记住,如果您在模块中添加了新方法。您需要:
yarn/npm install和Pod希望能有所帮助。
https://stackoverflow.com/questions/55024073
复制相似问题