teambit / envs

Component development environments for the Bit community
https://bit.dev/bit/envs
Other
63 stars 9 forks source link

Metro has encountered an error while trying to resolve module 'react-native' #143

Closed JoshK2 closed 4 years ago

JoshK2 commented 4 years ago

Describe the bug

This error is coming after exporting RN components and restarting the simulator when .bit folder is in the root of the project. image

We can solve this issue by adding a Regex to the default blacklist in metro.config.js file that will ignore .bit folder:

/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */
const blacklist = require('metro-config/src/defaults/blacklist');

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
  resolver: {
    blacklistRE: blacklist([/.bit\/.*/]),
  },
};

Specifications

JoshK2 commented 4 years ago

I wrote in the README of the compiler on how to solve this issue. https://github.com/teambit/envs/tree/master/packages/react-native#metro-has-encountered-an-error-while-trying-to-resolve-module-react-native