facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.12k stars 607 forks source link

Babel not Transforming Extra Modules #615

Open redreceipt opened 3 years ago

redreceipt commented 3 years ago

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

When specifying an extra node module in the config, Babel doesn't seem to be transforming the file properly:

metro.config.js

const extraNodeModules = {
  '@apollosproject/config': path.resolve(
    `${__dirname}/../../apollos-apps/packages/apollos-config/`
  ),
}

module.exports = {
  resolver: {
    extraNodeModules,
  },
};

Bundle Error:

error: bundling failed: Error: Unable to resolve module `@babel/runtime/helpers/interopRequireDefault` from `/Users/michael/Documents/Projects/apollos/apollos-apps/packages/apollos-config/react-native/index.js`: Module `@babel/runtime/helpers/interopRequireDefault` does not exist in the Haste module map

index.js file in question:

import NativeConfig from 'react-native-config';
...
...
...

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

A minimal example would be very hard to repro as I am "linking" external modules.

What is the expected behavior?

The bundle builds properly.

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.

RN: 60 Node: 15 Yarn: 1.22 OS: Mac 11

hmbrg commented 3 years ago

Did you ever find a solution to this? I'm facing the same problem.

My current workaround is just installing all dependencies again. It's a dirty hack and I'd like to clean that up in the future.

redreceipt commented 3 years ago

No. I ended up using a third party lib to feed in symlinks.

hmbrg commented 3 years ago

Can you elaborate on how exactly you achieved that? I would be beyond thankful.

redreceipt commented 3 years ago

Can you elaborate on how exactly you achieved that? I would be beyond thankful.

Use this library after running yarn link on your source dependencies so metro can resolve to the right folder.

https://github.com/Carimus/metro-symlinked-deps