React-Native无法解析本地npm module. co

2023-07-13  本文已影响0人  王家薪

准备做一个npm package管理依赖。在React-Native项目本地测试时报错。PS: t-library是包名

Error: Unable to resolve module t-library from /xxx/index.js: t-library could not be found within the project or in these directories:

安装方式尝试了npm install /path/t-librarynpm link两种方式,均有这个问题。
奇怪的是在node_modules目录下是可以找到t-library文件夹的,相关的代码也都在里面。

之后又创建了个非Reac-Native项目使用进行本地测试,发现是正常的。

猜测可能是React-Native的问题,最终发现原来是Metro不支持软连接
https://github.com/facebook/metro/issues/1

解决办法很简单,使用yarn, 参考链接:https://github.com/facebook/react-native/issues/29977

上一篇 下一篇

猜你喜欢

热点阅读