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

Importing files outside project directory does not work #269

Closed
bojan96 opened this issue Sep 27, 2018 · 4 comments
Closed

Importing files outside project directory does not work #269

bojan96 opened this issue Sep 27, 2018 · 4 comments

Comments

@bojan96
Copy link

bojan96 commented Sep 27, 2018

My folder structure is this:

ReactNativeTest
 |---   Lib/
 |         |--- lib.js
 |---   ReactNativeTest/
           |--- App.js
           |--- app.json, index.js, ...
   

Lib is shared between many projects

Inside App.js
Import lib from ../Lib/lib;
Currently metro has issue with symlinks in node_modules folder, so I thought why not include shared library using relative path, but this does not work either

error: bundling failed: Error: Unable to resolve module ../Lib/lib from D:\Projects\ReactNativeTest\ReactNativeTest\App.js: The module ../Lib/lib could not be found from D:\Projects\ReactNativeTest\ReactNativeTest\App.js. Indeed, none of these files exist:

  • D:\Projects\ReactNativeTest\Lib\lib(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
  • D:\Projects\ReactNativeTest\Lib\lib\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)

In the end, I solved this issue by copying Lib dir to RN project dir, and importing from './Lib/lib' but this is not ideal solution.
OS: Windows 10

@rafeca
Copy link
Contributor

rafeca commented Oct 1, 2018

Hi!

Metro has a config param where you can define folders that are outside of your projectRoot: it's called watchFolders. There's more information about it and other config params in: https://facebook.github.io/metro/docs/en/configuration#general-options

Closing the issue, please reopen if this does not solve it 😃

@rafeca rafeca closed this as completed Oct 1, 2018
@ivan-jorge001
Copy link

this doesn't work for me, I have the same project structure and when I import a js file it works perfectly but now if I import anything that isn't a .js (like png, svg, jpg) file it breaks, it doesn't display any error but just doesn't show the image. If put them within the project root then it works perfectly. please let me know if you need further details

@aleclarson
Copy link
Contributor

@ivan-jorge001 I would recommend reproducing the bug in a minimal repository if this is important to you.

@marioharper
Copy link

marioharper commented Nov 2, 2018

@rafeca looks like this does not work with .jpg's like @ivan-jorge001 pointed out above. I've created a reproducible project and have linked it in #289.

Here it is for your convenience: https://github.com/marioharper/metro-image-load-bug

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

No branches or pull requests

5 participants