Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest-haste-map: Haste module naming collision: -> namefunction <- #3295

Closed
esuarezz opened this issue Jan 28, 2020 · 15 comments
Closed

jest-haste-map: Haste module naming collision: -> namefunction <- #3295

esuarezz opened this issue Jan 28, 2020 · 15 comments
Labels
platform Issues tied to the general CLI platform question General question

Comments

@esuarezz
Copy link

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.

@dantasfiles
Copy link

dantasfiles commented Jan 29, 2020

@ashika01 ashika01 transferred this issue from aws-amplify/amplify-js Jan 29, 2020
@SwaySway SwaySway added functions Issues tied to the functions category pending-triage Issue is pending triage labels Jan 30, 2020
@yuth
Copy link
Contributor

yuth commented Jan 30, 2020

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.

@yuth yuth added platform Issues tied to the general CLI platform question General question and removed functions Issues tied to the functions category pending-triage Issue is pending triage labels Jan 30, 2020
@esuarezz esuarezz closed this as completed Feb 5, 2020
@radhikathakkar
Copy link

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?? "

@miekassu
Copy link

@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: amazon-archives/awsmobile-cli#172

@bilal-korir
Copy link

bilal-korir commented Apr 26, 2020

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.

@lissau
Copy link

lissau commented Apr 27, 2020

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,
      },
    }),
  },
};

@PatidarParth
Copy link

PatidarParth commented Jul 19, 2020

@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

@miekassu
Copy link

@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\/.*/]),
  },
};

@PatidarParth
Copy link

@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"
      },

@miekassu
Copy link

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

@JosephVasse
Copy link

Hello, i tried to add the blacklist as mentionned below,

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,
      },
    }),
  },
};

but it seems that i do not have "blacklist.js" file in my metro-config/src/defaults/ :

`error Cannot find module 'metro-config/src/defaults/blacklist'
Require stack:

  • /Users/josephvasse/Desktop/Villeo/metro.config.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/cosmiconfig/node_modules/import-fresh/index.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/cosmiconfig/dist/loaders.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/cosmiconfig/dist/createExplorer.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/cosmiconfig/dist/index.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/@react-native-community/cli/build/tools/config/readConfigFromDisk.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/@react-native-community/cli/build/tools/config/index.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/@react-native-community/cli/build/commands/install/install.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/@react-native-community/cli/build/commands/index.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/@react-native-community/cli/build/index.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/react-native/cli.js.
    Error: Cannot find module 'metro-config/src/defaults/blacklist'
    Require stack:
  • /Users/josephvasse/Desktop/Villeo/metro.config.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/cosmiconfig/node_modules/import-fresh/index.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/cosmiconfig/dist/loaders.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/cosmiconfig/dist/createExplorer.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/cosmiconfig/dist/index.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/@react-native-community/cli/build/tools/config/readConfigFromDisk.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/@react-native-community/cli/build/tools/config/index.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/@react-native-community/cli/build/commands/install/install.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/@react-native-community/cli/build/commands/index.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/@react-native-community/cli/build/index.js
  • /Users/josephvasse/Desktop/Villeo/node_modules/react-native/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object. (/Users/josephvasse/Desktop/Villeo/metro.config.js:8:20)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    info Run CLI with --verbose flag for more details.
    Process terminated. Press to close the window`

I checked as i found on the the net that is could be somewhere else, but it seems that there is no "blacklist.js" file in my project at all ...

Can someone help me ?

@flogy
Copy link

flogy commented May 6, 2021

@JosephVasse in newer versions of metro-config the function is now called exclusionList. So the resulting code would now look like this:

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

I also had to manually install metro-config as a dev dependency: npm i -D metro-config

@JosephVasse
Copy link

Yes, i finally figured it out.
I wasn't able to find this issue back to add the answer

Thank you for replying though

@miekassu
Copy link

After updating to Expo SDK41 this issue came back.
I needed to change previous rn-cli.config.js to metro.config.js (even though Im not using TS) and install @expo/metro-config as devDependency.

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform Issues tied to the general CLI platform question General question
Projects
None yet
Development

No branches or pull requests