简体   繁体   English

React Native:在项目目录之外导入模块

[英]React Native: Import modules outside of project directory

I have built a web app using React and Flux. 我使用React和Flux构建了一个Web应用程序。 Now I am trying to build a mobile app for the same in React Native. 现在我正在尝试在React Native中构建一个移动应用程序。 Since except for the view components everything is going to be almost the same, I have placed the RN app source code inside the main repo and plan to use the modules from the parent repo. 由于除了视图组件外,一切都将基本相同,我已将RN应用程序源代码放在主仓库中,并计划使用父仓库中的模块。

My directory structure is something like this - 我的目录结构是这样的 -

main_app
 |-- src
     |-- app 
     |    |-- some_module_1.js
     |    |-- some_module_2.js
     +-- rn_app
          |-- app
          |    |-- some_rn_module.js
          |   
          |-- index.ios.js

Now in my some_rn_module.js , I'm trying to import some_module_1 - 现在在我的some_rn_module.js ,我正在尝试导入some_module_1 -

import SomeModule1 from '../../../app/some_module_1';

This throws an Unable to resolve module exception. 这会抛出一个Unable to resolve module异常。 Is this a problem with the RN packager? 这是RN打包机的问题吗?

我想你可以使用这个https://docs.npmjs.com/cli/link的 npm link

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM