Search code examples
amazon-web-servicesreact-nativeaws-lambdaamazon-dynamodbaws-amplify

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?


Solution

  • 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.