question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing files outside main directory

See original GitHub issue

Where I have a directory for mobile and a directory for web which I’d like to share some common code (utils, etc). Currently, if I import a file outside the root directory of my generated app (outside where App.js is located), I get an error with no file found.

Is this by design? Will this be supported in the future and is this an Expo limitation or RN?

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:22 (4 by maintainers)

github_iconTop GitHub Comments

31reactions
roblafevecommented, Nov 12, 2017

@pankaj-arunsingh I can’t find the original issue where I finally found this but basically add only the external module path you want to import. In my case my module had a dependency on React and React-Native so those are added as extraNodeModules. Hope this helps.

Inside rn-cli.config.js:

var path = require("path");
const metroBundler = require('metro-bundler');

var config = {
  extraNodeModules: {
    "react-native": path.resolve(__dirname, "node_modules/react-native"),
    "react": path.resolve(__dirname, "node_modules/react"),
  },
  getProjectRoots() {
    return [
      // Keep your project directory.
      path.resolve(__dirname),
      path.resolve(__dirname, "../native"), // path to the external module
    ];
  }
}
module.exports = config;
5reactions
pankaj-arunsinghcommented, Nov 12, 2017

This is crazy. Please post a solution to this problem if anyone finds it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python - Import module outside directory
If the module exists in the same directory as the file, we can directly import it using the syntax import module_name. But if...
Read more >
How to access a module from outside your file folder in ...
The simplest way is to modify the sys.path variable (it defines the import search path): # Bring your packages onto the path import...
Read more >
How to import files from outside of root directory with React ...
So we're going to see how to directly reference any file outside of root directory.. Consider this example: common - components - Utils.ts,...
Read more >
Python File Importation into Multi-Level Directory Modules ...
Let's use a Python project with a directory structure (as shown below) to demonstrate how easy it can be to import from a...
Read more >
Python — How to Import Modules From Another Folder?
The most Pythonic way to import a module from another folder is to place an empty file named __init__.py into that folder and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found