Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including source code from outside root project #639

Closed
vladp opened this issue Aug 17, 2019 · 5 comments
Closed

Including source code from outside root project #639

vladp opened this issue Aug 17, 2019 · 5 comments
Labels
question Further information is requested

Comments

@vladp
Copy link

vladp commented Aug 17, 2019

Having difficulties figuring out how to include js source code from outside the root project

My index.android.js has
import { functionX} from './../rn.common/src/js.app/SomeFunctionsThatUseRN'

The above, unfortunately causes an error.
I saw how to solve it with
getProjectRoots of the old rn-cli.config.js.
However, I could not find in migration docs, of how to do this with react-native-community/cli

So I tried what I thought might work (below)... but no success.


module.exports = {
    project: {
	ios: {},
	android: {
	    "sourceDir": "../a/andrapp1/app/src",//bundler must know the root of the java source of the app 
	    "packageName":"com.myapp1"    
	},
    },
    assets: ['./../rn.common/src/js.app/img'], 
    dependencies: {
    'rn.common': {
      root: '../rn.common',   //<-- this does not work
    },
  },
};



``
my environment:

> react-native info
info Fetching system and libraries information...
System:
    OS: Windows 10
  Binaries:
    Node: 12.8.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.6.0 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.5.0 - C:\Program Files\nodejs\npm.CMD
@vladp vladp added the question Further information is requested label Aug 17, 2019
@thymikee
Copy link
Member

You'll need to configure Metro bundler using metro.config.js, look for projectRoot and/or watchFolders

@vladp
Copy link
Author

vladp commented Aug 17, 2019

Thank you for pointing to metro.config.js. I would not even think to look there.
Unfortunately watchFolders does not fix what directories are allowed in import statements.

And if I set projectRoot to the shared directory (rn.common) then nothing else works (as it cannot find index.android.js) and so on.

@thymikee
Copy link
Member

@vladp
Copy link
Author

vladp commented Aug 17, 2019

Thank you for the pointers!. I was looking at those as well.
I think the difference is that I am not looking to share node_modules from ../common
I am just looking to include sources of javascript files there.

The part where they showed how to use metro resolver to 'expose' all the node_modules in root dir
to modules from outside of root dir, is neat though.

Thank you for your help, at any rate, it seems that I need to chase the whole problem->solution with metro folks.

@damianham
Copy link

After finding no way to solve this I ended up using gulp to watch external modules and copy them into node_modules of my RN app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants