question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bundler looks in directories besides node_modules for node_modules

See original GitHub issue
yarn
mv node_modules xxx
yarn
yarn react-native start
# load app in a simulator
This warning is caused by a @providesModule declaration with the same name across two different files.
jest-haste-map: @providesModule naming collision:
  Duplicate module name: react-animated
  Paths: /path/to/my/project/node_modules/react-native/Libraries/Animated/release/package.json collides with /path/to/my/project/xxx/react-native/Libraries/Animated/release/package.json

error: bundling failed: ambiguous resolution: module `/path/to/my/project/index.js` tries to require `react-native`, but there are several files providing this module. You can delete or fix them:

This seems to be unexpected behavior. If the convention is for node modules to live under node_modules, why would Metro Bundler take it upon itself to look anywhere else?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

3reactions
ulfgebhardtcommented, Dec 6, 2017
  • Node.js Version: v8.9.1
  • OS: Windows & Mac
  • Scope (install, code, runtime, meta, other?): runtime/other
  • Module (and version) (if relevant): React-Native & Electron

I use React-Native in combination with Electron to build iOS, Android, Desktop and Webversions of my Application. Electron generates a folder node_modules under ressource in its output. This folder is required to run the Desktop Application. Once the Desktop Version is compiled, node fails to build the iOS and Android, aswell as the Web Application since it will find two node_modules folders, containing duplicate modules.

This results in following errors:

Scanning folders for symlinks in D:\sources\demokratie-live\democracy-client\node_modules (66ms)
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚  Running Metro Bundler on port 8081.                                       β”‚
 β”‚                                                                            β”‚
 β”‚  Keep Metro Bundler running while developing on any JS projects. Feel      β”‚
 β”‚  free to close this tab and run your own Metro Bundler  instance if you    β”‚
 β”‚  prefer.                                                                   β”‚
 β”‚                                                                            β”‚
 β”‚  https://github.com/facebook/react-native                                  β”‚
 β”‚                                                                            β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Looking for JS files in
   D:\sources\demokratie-live\democracy-client


Metro Bundler ready.

Loading dependency graph, done.
Bundling `index.js`  [development, non-minified]  0.0% (0/1), failed.
error: bundling failed: ambiguous resolution: module `D:\sources\demokratie-live\democracy-client\index.js` tries to require `react-native`, but there are several files providing this module. You can delete or fix them:

  * `D:\sources\demokratie-live\democracy-client\dist\win-unpacked\resources\app.asar.unpacked\node_modules\react-native\package.json`
  * `D:\sources\demokratie-live\democracy-client\node_modules\react-native\package.json`

The question is: How do I tell metro bundler to ignore a certain node_modules folder or specify which one it should use?

Rel: https://github.com/demokratie-live/democracy-client/tree/desktop Rel: https://github.com/nodejs/help/issues/1011

Grüße Ulf

❀️

1reaction
OisinOKeeffecommented, Feb 14, 2018

I was able to fix this in my case by adding a rn-cli.config.js file to the root of my monorepo with the following content:

const metroBundler = require(β€˜metro-bundler’);

module.exports = { getBlacklistRE: function() { return metroBundler.createBlacklist([/NAME_OF_FOLDER_TO_EXCLUDE/.*/]); } };

When I switch from project to project I can just update the excluded folder and I am good to go. Two different versions of React-Native in the same monorepo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should I check in folder "node_modules" to Git when ...
I am the Node language owner at Heroku and the answer is simple: No. Do not check node_modules in to Heroku apps. –...
Read more >
folders
Cycles, Conflicts, and Folder Parsimony. Cycles are handled using the property of node's module system that it walks up the directories looking for...
Read more >
What Happened When I Peeked Into My Node_Modules ...
I opened up babel-core in vim, then turned off my computer because Ctrl-C wasn't exiting, then opened babel-core in Sublime Text 2. module....
Read more >
API - esbuild
In node, you can load a module using node --experimental-modules file.mjs . Note that node requires the .mjs extension unless you have configured...
Read more >
Dependency resolution
Parcel includes shims for many builtin Node.js modules, e.g. path and url . When a dependency specifier references one of these module names,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found