Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

jest-haste-map: @providesModule naming collision: Duplicate module name #172

Open
C2P1 opened this issue Jul 24, 2018 · 42 comments
Open

jest-haste-map: @providesModule naming collision: Duplicate module name #172

C2P1 opened this issue Jul 24, 2018 · 42 comments
Assignees
Labels

Comments

@C2P1
Copy link

C2P1 commented Jul 24, 2018

Hello,

Trying to run npm start on my project is now giving me the following error:

Error: jest-haste-map: @providesModule naming collision:
Duplicate module name: app
Paths:
/Users/c2p1/apps/awsmobilejs/#current-backend-info/cloud-api/Table/package.json
collides with
/Users/c2p1/apps/awsmobilejs/backend/cloud-api/Table/package.json

both of these package.json are identical and have the field:
"name": "app"

I am now currently unable to build and run my app due to this.

Whenever I use the command awsmobile pull I enter Yes to the question

Sync corresponding contents in backend/ with #current-backend-info/

and it to me it appears like this is where the issue is created. Should I not be syncing the contents? How do I fix this so I can build my project?

Thanks!

@UnleashedMind
Copy link
Contributor

UnleashedMind commented Jul 24, 2018

The contents in the #current-backend-info folder and the backend folder are pretty much the same after each synchronization with the cloud.
Then you develop your work in the backend and push the changes up to the cloud.
That's the reason you see the two packages named the same.

Jest is a unit test framework, it's not part of the awsmobile-cli.
I'd suggest you to exclude the #current-backend-info folder from being tested by jest-haste-map, and you should be able to build your project fine.

@C2P1
Copy link
Author

C2P1 commented Jul 27, 2018

Thanks for your reply!

I know that this used to be fine, as I've had no problems before, but since upgrading to react-native 0.56.0 this issue has started happening. Right now, I currently can't find how to exclude the #current-backend-info from the jest-haste-map. I will keep looking into it, but it seems odd that to be able to use awsmobile I then have to manually exclude some of the files it installs.

On the topic of awsmobile, is there any reason my project needs awsmobile folders prepended by a '~'? Can these be deleted?

@UnleashedMind
Copy link
Contributor

UnleashedMind commented Jul 27, 2018

awsmobile folders with name prefix '~' are backups, awsmobile-cli does not want you to loose your files, so if the cli is creating the contents in the awsmobilejs folder anew, it backs up the original contents in the backup folders.
If you don't need those files, you can delete them, the cli doesn't use them.

@juang97
Copy link

juang97 commented Jul 28, 2018

Hi,
I am also running into the same problem but instead i have the package.json colliding with two different tables on my Cloud-api folder
screen shot 2018-07-28 at 12 47 04 pm

This is my folder hierarchy
screen shot 2018-07-28 at 12 48 57 pm

any ideas on how to fix this? Thank you

@C2P1
Copy link
Author

C2P1 commented Jul 29, 2018

Hi @juang97, did this issue start being a problem after you had run a npm install or npm audit fix ?

@C2P1
Copy link
Author

C2P1 commented Jul 29, 2018

@UnleashedMind, if I delete #current-backend-info will things still work? I have yet to find a way to exclude it from Jest-Haste-Map and this is preventing my app from running.

Next time when I do an

awsmobile pull

and say yes to sync info, will I then get a new #current-backend-info folder created? I

@juang97
Copy link

juang97 commented Jul 30, 2018

@C2P1. I was able to patch this issue by blacklisting the Table name under the awsmobile folder. This approach doesnt exactly fix the problem but everything is working as expected for me. If you are interested, take a look here https://stackoverflow.com/questions/41813211/how-to-make-react-native-packager-ignore-certain-directories

@michaelcuneo
Copy link

I'm having this exact same problem. I was just about to post and ask a question about it... but it's here already.

(node:90796) UnhandledPromiseRejectionWarning: Error: jest-haste-map: @providesModule naming collision:
Duplicate module name: app
Paths: /Users/mjc128/Desktop/ReactNativeKoalaCall/awsmobilejs/backend/cloud-api/globalSettings/package.json collides with /Users/mjc128/Desktop/ReactNativeKoalaCall/awsmobilejs/backend/cloud-api/imageSets/package.json

I've tried multiple solutions, but nothing... I can no longer compile my app. I've tried clearing the jest cache map on run, and nothing, tried removing react-native and reinstalling react-native and nothing, I also tried removing the entire node_modules folder and reinitialising, but nothing.

@michaelcuneo
Copy link

As stated by @juang97 I followed the same procedure, and added the following to a file nammed rn-cli.config.js in the root of my project...

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

module.exports = {
  getBlacklistRE: function() {
    return blacklist([/awsmobilejs\/.*/]);
  }
};

Works 100% fine since then.

Thanks guys.

XWilliamY added a commit to XWilliamY/prototype2_part2 that referenced this issue Aug 9, 2018
…current-backend-info and backend, both under awsmobilejs. I followed along to the responses at this github link: amazon-archives/awsmobile-cli#172 and was able to resolve this issue by creating rn-cli.config.js and adding it to the root of my project. A copy of it can be found in the same folder as App.js
@7772
Copy link

7772 commented Aug 23, 2018

@michaelcuneo 's solution worked for me. Thanks :)

@Ivanrs297
Copy link

Hi, im having this problem too, but with react-native module. The build is succeeded, but when it start to run the app the error show the following:

whatsapp image 2018-09-25 at 12 53 59 pm

I tried to delete and reinstall node_modules, clear cache, but nothing.

@emlynmac
Copy link

Yup, I'm seeing the same thing @Ivanrs297. I'm trying to figure out how to block jest from peering into my iOS build area now...

@emlynmac
Copy link

And so what I did was to rename the package.json -> package.json-off in the ios/Pods/React directory and it's good. If anyone knows how to tell jest-haste-map to ignore the iOS directory, that would be great to know. @Ivanrs297

@shinriyo
Copy link

it's good?
I renamed package.json -> package.json-off in ios/Pods/React
com.facebook.react.JavaScript (9): EXC_BAD_ACCESS happened...

@michaelcuneo
Copy link

react and react-native packages should be installed globally and not within any packages node_modules folder... or it’ll break it like this.

@shinriyo
Copy link

My problem was AdMob plugin.
I removed pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons' from my ios/Podfile and pod install in ios folder again.
I resolved.

@emlynmac
Copy link

@shinriyo if it doesn't work for you, maybe you have something else going on.
@michaelcuneo I find that statement hard to believe - as the react-native init myApp includes react and react-native into the node_modules directory.

@Ivanrs297
Copy link

@emlynmac thanks, it works but this is a temporary solution, we hope this can be fixed in newer versions

@michaelcuneo
Copy link

@emlynmac I explained what I meant really poorly. I mean, if you have a project called Potato, with node_modules inside, it can have react-native in there... but if you have a project inside node_modules called 'potato_helper, which also houses it's own node_modules folder, and dependencies, but one of these dependencies is react-native, and is a different version to that of the global node_modules folder in the main package of Potato... issues can occur, and cause the declaration definition issues... at least that's what has caused issues for me in the past.

@ovpv
Copy link

ovpv commented Nov 27, 2018

@emlynmac I explained what I meant really poorly. I mean, if you have a project called Potato, with node_modules inside, it can have react-native in there... but if you have a project inside node_modules called 'potato_helper, which also houses it's own node_modules folder, and dependencies, but one of these dependencies is react-native, and is a different version to that of the global node_modules folder in the main package of Potato... issues can occur, and cause the declaration definition issues... at least that's what has caused issues for me in the past.

@michaelcuneo Did anyone find the solution for this issue?

@psalmdawg
Copy link

I am having the same issue, not managed to a solution.
where do you find the rn-cli.config.js in the project?

@wilywork
Copy link

wilywork commented Dec 5, 2018

hi i find the problem. two folder node_modules, example: node_modules and node_modules_test.
clear the folder node_modules_test.
it's work for me.

@shuiRong
Copy link

shuiRong commented Dec 29, 2018

I am having the same issue, not managed to a solution.
where do you find the rn-cli.config.js in the project?

@psalmdawg
you can create one look here

@nara
Copy link

nara commented Jan 18, 2019

the fix rn-cli.config.js and changing the blacklist folder name to #current-cloud-backend worked for me.


// blacklist is a function that takes an array of regexes and combines
// them with the default blacklist to return a single regex.

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

@elorzafe
Copy link
Contributor

I can confirm this works
rn-cli.config.js

module.exports = {
 resolver: {
   blacklistRE: /amplify\/.*/
 }
};

@abdul-elah-js
Copy link

For future reference, this solution worked for me

https://stackoverflow.com/a/51372213/5673311

@arhmnsh
Copy link

arhmnsh commented Mar 5, 2019

hi i find the problem. two folder node_modules, example: node_modules and node_modules_test.
clear the folder node_modules_test.
it's work for me.

@wilywork's reply worked perfectly for me, I made a backup of node_modules folder as node_modules_bkp.
Removed the backup folder, worked!

@GreenRidingHood
Copy link

@abdul-elah-js do you mind share solution, link is not working, thanks

@ryanjones
Copy link

@nara's solution worked well for me here:

rn-cli.config.js


module.exports = {
 resolver: {
   blacklistRE: /#current-cloud-backend\/.*/
 }
};
> react-native start --config=rn-cli.config.js --resetCache

When I did blacklistRE: /amplify\/.*/ it started to throw errors on the amplify modules within the solution (ie. @aws-amplify/auth doesn't exist) which makes sense since they weren't included.

> react-native --version
react-native-cli: 2.0.1
react-native: 0.59.1

@jimji1005
Copy link

Also if you are using typescript, I added the blacklist in metro.config.js instead

@roychoo
Copy link

roychoo commented Apr 16, 2019

just to iterate @jimji1005 said,

if you are using typescript, put this in your metro.config.js NOT rn-cli.config.js

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

@janhesters
Copy link

janhesters commented Jun 18, 2019

What should you do if you use Expo? NVM.

Creating a file rn-cli.config.js in the root of my projecting worked with Expo.

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

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

@RoniqueRicketts
Copy link

What should you do if you use Expo? NVM.

Creating a file rn-cli.config.js in the root of my projecting worked with Expo.

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

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

I have tried this and I am still getting the same error. I am running the app on Android Studio. Any pointers?

@janhesters
Copy link

@RoniqueRicketts I only tested on iOS, sorry 🤷🏻‍♂️

@RoniqueRicketts
Copy link

RoniqueRicketts commented Jun 19, 2019

@janhesters After creating the rn-cli.config.js file should I call it from anywhere else? Because when I run the command react-native run-android --config=rn-cli.config.js --config is not a part of the CLI.

@janhesters
Copy link

@RoniqueRicketts No you won't need to call it (at least I didn't).

@RoniqueRicketts
Copy link

It’s not working for me.

@AndreiCatalinN
Copy link

running the tests with the --silent option resolved the issue for me

@RoniqueRicketts
Copy link

RoniqueRicketts commented Jun 26, 2019 via email

@AndreiCatalinN
Copy link

Silent prevents tests from printing messages through the console.

@hoonblizz
Copy link

@roychoo Works like a charm. Thank you!

@dantasfiles
Copy link

So for React Native 0.61 without Expo (run with "npx react-native run-android"), changing the existing metro.config.js (not rl-cli.config.js) seems to work

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests