Amplify-cli: jest-haste-map: Haste module naming collision: -> namefunction <-

Created on 29 Jan 2020  路  10Comments  路  Source: aws-amplify/amplify-cli

To Reproduce
1) amplify add function
2) function is created locally correctly
3) amplify push and pushed correctly
4) when I run expo I get:

INFO
22:55
Starting Metro Bundler on port 19001.
ERROR
22:55
jest-haste-map: Haste module naming collision: funcionlambdaparadietas
  The following files share their name; please adjust your hasteImpl:
    * <rootDir>/amplify/#current-cloud-backend/function/funcionlambdaparadietas/src/package.json
    * <rootDir>/amplify/backend/function/funcionlambdaparadietas/src/package.json

ERROR
22:55
Failed to construct transformer:  { Error: Duplicated files or mocks. Please check the console for more info
    at setModule (/Users/elio/WebstormProjects/Hapsto-app/node_modules/jest-haste-map/build/index.js:620:17)
    at workerReply (/Users/elio/WebstormProjects/Hapsto-app/node_modules/jest-haste-map/build/index.js:691:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  mockPath1:
   'amplify/#current-cloud-backend/function/funcionlambdaparadietas/src/package.json',
  mockPath2:
   'amplify/backend/function/funcionlambdaparadietas/src/package.json' }
ERROR
22:55
(node:61503) UnhandledPromiseRejectionWarning: Error: Duplicated files or mocks. Please check the console for more info
    at setModule (/Users/elio/WebstormProjects/Hapsto-app/node_modules/jest-haste-map/build/index.js:620:17)
    at workerReply (/Users/elio/WebstormProjects/Hapsto-app/node_modules/jest-haste-map/build/index.js:691:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:61503) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:61503) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
INFO
22:55
Tunnel ready.

platform question

Most helpful comment

For React Native 0.6x configure the blacklist in metro.config.js instead of rn-cli.config.js, as per this answer

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

All 10 comments

Amplify CLI puts all the backend resources in a <project-root>/amplify/ folder. This folder does not contain any files that will be used in the frontend code and should be ignored when building/testing frontend code.

Amplify CLI puts all the backend resources in a <project-root>/amplify/ folder. This folder does not contain any files that will be used in the frontend code and should be ignored when building/testing frontend code.

" so what is the solution for this?? "

@radhikathakkar this worked for me.
create rn-cli-config.js to root folder of ur project.

const blacklist = require('metro').createBlacklist;

module.exports = {
  resolver: {
    blacklistRE: blacklist([/#current-cloud-backend\/.*/]),
  },
};

found from: https://github.com/amazon-archives/awsmobile-cli/issues/172

In my case, I'm using ReactNative CLI. Updating the metro.config.js file with the following has worked for me:

module.exports = {
  resolver: {
    blacklistRE: /#current-cloud-backend\/.*/,
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false,
      },
    }),
  },
};

I'm not using Expo, but seems like if you are using Expo you should update/create rn-cli.config.js at the root of your project, instead.

For React Native 0.6x configure the blacklist in metro.config.js instead of rn-cli.config.js, as per this answer

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

@miekassu I have tried the expo solution but now get this error when I try to run the app. Any idea?

Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.

runApplication
    AppRegistry.js:189:6
callFunctionReturnFlushedQueue
    [native code]:0

@PatidarParth after Expo 38 SDK update I had same error.
I needed to update rn-cli.config.js as following:

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

@miekassu Do you call the rn-cli.config.js anywhere? For example, do I need to include it in the projectOpts within the app.json like below?

    "packagerOpts": {
      "config": "./rn-cli.config.js"
      },

@PatidarParth file is just included in root. Metro picks it up automatically. Good luck!

Was this page helpful?
0 / 5 - 0 ratings