Android 在React Native中导入文件

Android 在React Native中导入文件,android,react-native,Android,React Native,我的目录结构如下所示: web/ js/ Test.js mobile index.android.js 在index.android.js中,我添加了来自“../web/js/Test的导入测试。但是,我得到了这个错误: (node:590) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 12): UnableToResolveError: Unable to reso

我的目录结构如下所示:

web/
  js/
    Test.js
mobile
  index.android.js
index.android.js
中,我添加了来自“../web/js/Test的
导入测试。但是,我得到了这个错误:

(node:590) UnhandledPromiseRejectionWarning:
Unhandled promise rejection (rejection id: 12):
UnableToResolveError:
Unable to resolve module `../web/js/Test.js` from `/mnt/d/.../mobile/index.android.js`:
Directory /mnt/d/.../web/js/Test.js doesn't exist
我试着重新运行
react native start
,但仍然不起作用。我没有安装Watchman,但我认为这不是问题所在。

1)在移动文件夹的package.json中添加为依赖项:

"dependencies": {
   //...your deps here +
   "commonWebAndMobileDeps": "file:../web/js/common"
}
2) 确保Test.js位于
web/js/common

3) 在移动文件夹中运行npm安装

4) 在移动设备中,使用以下工具导入它:

import Test from 'commonWebAndMobileDeps/Test'

我不知道你想做什么。您是否试图在React Native中重用React web代码?React Native是否允许您从项目根目录及其嵌套文件夹之外的任何位置导入js文件?似乎您缺少了您提到的导入的结束单报价,尽管这可能是您的输入错误?另一个问题是如何定义测试。是否正确导出该组件?我们需要进一步的信息来确定发生了什么。