Justin Priede
Justin Priede

Reputation: 119

AWS Amplify Duplicate Error: Duplicated files or mocks

I set up a new amplify, added auth, and a post confirmation lambda function to move user data into DynamoDB. When I run NPM start, I get this error:

Failed to construct transformer: DuplicateError: Duplicated files or mocks. Please check the console for more info at setModule (\MyDemo\node_modules\jest-haste-map\build\index.js:543:17) .js:426:22 {

mockPath1: 'amplify#current-cloud-backend\function\FreshAuthPostConfirmation\src\package.json',

mockPath2: 'amplify\backend\function\FreshAuthPostConfirmation\src\package.json' } '''

Based on what I have read, #current-cloud-backend gets created by amplify, based on the files in the backend folder. It seems like that package.json is supposed to be there, but I am not sure why it is an error. I saw somewhere that I should just delete the subclass duplicate file, which I assumed to be the one in #current-cloud-backend, but amplify is going to keep producing this error every time I push to it, how do I avoid this from happening at all?

Upvotes: 4

Views: 2865

Answers (2)

jd11
jd11

Reputation: 129

I run into the same problem. I'm using Expo SDK 48 and Amplify with lambda functions To add metro.config.js file into expo project, follow: https://docs.expo.dev/guides/customizing-metro/

  1. run npx expo customize metro.config.js in project terminal
  2. inside generated metro.config.js file, modify it to:
const { getDefaultConfig } = require('expo/metro-config');
const exclusionList = require('metro-config/src/defaults/exclusionList');

const config = getDefaultConfig(__dirname);

config.resolver.blacklistRE = exclusionList([/amplify\/#current-cloud-backend\/.*/]);

module.exports = config;

No need to install any extra npm packages (I see some answers ask you to install metro-confic dev dependencies, which is not needed according to my experiment, it even brought EAS build failures...)

Then I tried npx expo start and eas build -p ios, both works successfully.

Upvotes: 3

eli6
eli6

Reputation: 1034

There is a discussion about this error in this Amplify GitHub Issue. The file package.json appears twice to jest-haste-map, and the solution is to explicitly ignore the #current-cloud-backend folder when building and starting your app.

The solution to the problem depends on your version of React Native: here you find an overview of how exlusion of files work for different versions. For example, you can create a metro.config.js file with the following contents to exclude the #current-cloud-backend:

const exclusionList = require('metro-config/src/defaults/exclusionList');
module.exports = {
  resolver: {
    blacklistRE: exclusionList([/#current-cloud-backend\/.*/])
  }
};

And install metro-config as a dev dependency. If that doesn't work there are some other solutions in the links that you can try out.

Upvotes: 18

Related Questions