'jest-haste-map: Haste module naming collision (AWS, RN)

I have a React-native project with AWS Amplify.

In the root directory, there is an amplify folder.

Inside this amplify folder, there is a backend folder, and a #current-cloud-backend folder.

These two are basically identical.

When I try to start my project with npm run start I receive this error:

  The following files share their name; please adjust your hasteImpl:
    * <rootDir>/amplify-backup/backend/function/cxLoyaltyMainAppVerifyAuthChallengeResponse/src/package.json
    * <rootDir>/amplify/#current-cloud-backend/function/cxLoyaltyMainAppVerifyAuthChallengeResponse/src/package.json

And it is complaining that inside these two folders, each lambda function has it's own package.json, in which they are named identical to their counterpart folder.

What I have done so far

I have found many people mentioning to put modulePathIgnorePatterns: ['<rootDir>/build'] inside of my root package.json under jest. Some also say to put it inside of jest.config.js which I cannot find anywhere.

I have also tried creating a root rn-cli.config.js and added

module.exports = {
   resolver: {
       blacklistRE: blacklist( [
           /node_modules\/.*\/node_modules\/react-native\/.*/,
       ] )
   },
};

which also does not work.

I am really running out of ideas here, anyone have any ideas? Thank you



Solution 1:[1]

I am using the Expo CLI and was having the same problem.

The solution that worked for me: metro.config.js at the root directory. (instead of rn-cli.config.js)

const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
  resolver: {
    blacklistRE: blacklist([/#current-cloud-backend\/.*/]),
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
};

Solution 2:[2]

UPDATE 2022! Just change the folder of the previous answer. It´s no longer defaults/blacklist, but defaults/exclusionList. So the solution:

I am using the Expo CLI and was having the same problem.

The solution that worked for me: metro.config.js at the root directory. (instead of rn-cli.config.js)

const blacklist = require('metro-config/src/defaults/exclusionList');
module.exports = {
  resolver: {
    blacklistRE: blacklist([/#current-cloud-backend\/.*/]),
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
};

Solution 3:[3]

Adding the below snippet in the metro.config.js file worked for me

I am using:

react-native-cli: 2.0.1 react-native: 0.63.4 amplify: 5.3.0

 const exclusionList = require('metro-  config/src/defaults/exclusionList');
 module.exports = {
   resolver: {
     blacklistRE: exclusionList([/#current-cloud-backend\/.*/]),
   },
   transformer: {
     getTransformOptions: async () => ({
       transform: {
         experimentalImportSupport: false,
         inlineRequires: false,
       },
     }),
   },
 };

Also, you will need to install metro-config as a dependency by running npm i -D metro-config

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matt Ke
Solution 2 Illya Grytsayev
Solution 3 Larry DaBig Meech