9

I am trying to use a package from a relative path and I have done npm install ../../ExamplePackage and react-native install ../../ExamplePackage. These packages are relative by multiple levels and not just one.

I am getting the following errors

error: bundling failed: Error: Unable to resolve module `ExamplePackage` from `/Users/vikasagr/workspace/test/ReactNative/MyPackage/src/index.js`: Module `ExamplePackage` does not exist in the Haste module map

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
  1. Clear watchman watches: `watchman watch-del-all`.
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.
    at ModuleResolver.resolveDependency (/Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:161:1460)
    at ResolutionRequest.resolveDependency (/Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:91:16)
    at DependencyGraph.resolveDependency (/Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/node-haste/DependencyGraph.js:272:4579)
    at dependencies.map.relativePath (/Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/DeltaBundler/traverseDependencies.js:376:19)
    at Array.map (<anonymous>)
    at resolveDependencies (/Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/DeltaBundler/traverseDependencies.js:374:16)
    at /Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/DeltaBundler/traverseDependencies.js:212:33
    at Generator.next (<anonymous>)
    at step (/Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:313)
    at /Users/vikasagr/workspace/test/ReactNative/MyPackage/node_modules/metro/src/DeltaBundler/traverseDependencies.js:297:473

I tried all the steps but nothing worked. I also tried haul but that wasn't also working for me.

8
  • is the ExamplePackage real npm package? it has package.json of its own? Commented Apr 9, 2018 at 10:52
  • Yes. It has a package.json but its not on NPM Commented Apr 9, 2018 at 11:42
  • 1
    after you do npm install ../../ExamplePackage you see it added in project' package.json? Commented Apr 9, 2018 at 11:57
  • yes, I do see it in package.json Commented Apr 9, 2018 at 12:19
  • is this relevant: stackoverflow.com/questions/44061155/… ? Commented Apr 9, 2018 at 15:42

2 Answers 2

9

Symlinks were probably causing your problem. npm install with a local path installs libraries in node_modules with a symlink pointing to the local path of the package. Unfortunately this causes an issue with the react native metro bundler (" does not exist in the Haste module map").

I had the same issue with npm install. react-native install works for me, and that does not create symlinks.

Using wml is another good approach. It replicates the behavior of a symlink by automatically copying changes between your local library and its installed copy in node_modules.

See https://github.com/facebook/react-native/issues/23327 for a similar issue.

1
  • 1
    Symlink is not copying changes, it is really a link to a disk location Commented Apr 21, 2021 at 15:16
3

You can try WML. https://www.npmjs.com/package/wml

What it does:

replaces npm link with something that actually works!

It worked for me !

Cheers

1
  • To me, it log stdout when I change content of a watched file, but looking at the destination, it is still using the old file. Commented Apr 21, 2021 at 15:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.