Help with resolving extra node modules with metro.config.js

Expo version:
“expo”: “~38.0.8”,

React native version:
“react-native”: “https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz”,

Hey, I’m trying to add extra node module aliases to the metro resolver config. I’m doing this because I want to import some local node modules located in different folders from the main expo app folder while developing locally, without having to npm publish them every time I make a change. I would normally just do npm link, but since the metro bundler does not support symlinks, that does not work.

So the only solution I could come up with was adding a custom metro.config.js, adding a resolvers option, and setting customNodeModules to point to the local folders that contain these modules i’m trying to work on. E.g. what’s documented in the following links: Configuring Metro | Metro

This is my metro.config.js:

const path = require('path')

const extraNodeModules = {
  test: path.resolve(__dirname, '..', 'test')
}

module.exports = {
  resolver: {
    extraNodeModules
  }
}

It feels like the metro.config.js is completely ignored because I get the exact same error when trying to import my “test” module whether I have the metro.config.js or not:

Restarting Metro Bundler...
Starting Metro Bundler on port 19003.
Failed building JavaScript bundle.
Unable to resolve "test" from "src/App.js"
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.