react-native-create-library: Module `react` does not exist in the Haste module map. for library with only JS(react) code

i created a library using react-native-create-library named myLib and i have a RN app from react-native-cli named myApp.

The library “myLib” does not contain any native code and only JS code which imports react(basically made a component that i want to be shared), here is the package.json

{ “name”: “myLib”, “version”: “1.0.0”, “description”: “Set of components to be used throught the app”, “main”: “index.js”, “scripts”: { “test”: “echo "Error: no test specified" && exit 1” }, “keywords”: [ “react-native”, “basic-components” ], “author”: { “name”: “Ullas”, }, “license”: “”, “deprecated”: false, “dependencies”: { “apisauce”: “0.15.2”, “react-native-navbar”: “2.1.0” }, “peerDependencies”: { “react”: “16.3.1”, “react-native”: “0.55.4” } }

when i link this to the RN app “myApp” i get the error :

error: bundling failed: Error: Unable to resolve module react from /Users/ullas/Desktop/myLib/index.js: Module react does not exist in the Haste module map.

even though i have react as part of my node_modules for myApp project. How can i run this and use the dependencies provided by the peer project for my library rather then define dependencies of its own and duplicating the same?

need help 😦

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 13
  • Comments: 20 (3 by maintainers)

Most upvoted comments

got it resolved by using “react-native start --reset-cache”, the reference changed from Desktop to node_modules.

Delete your node_module and run npm install

Similar error said my lib does not exist in the Haste module map. None of above resolve the issue.

fixed by npm add @babel/runtime

@evanjmg Do you mean react-native link? Unfortunately you cannot symlink a react native package via npm link. This is a problem with the metro bundler and you can follow the issue here: facebook/metro#1

I’m confused by React-Native’s official documentation, specifically:

After [running react-native-create-library] you will navigate into MyLibrary folder and install the npm package to be locally available for your computer by doing:

$ npm install

After this is done you can go to your main react app folder (which you created by doing react-native init MyApp)

  • add your newly created module as a dependency in your package.json
  • run npm install to bring it along from your local npm repository.

It seems to imply that running npm install in the newly created library directory that npm will know to look here when instructed to install the package. This did not work for me, and my attempt to install it by directly referencing the file brought me here, as the Haste map did not follow the sym-link.

Are our options really just:

  1. push every change to a remote repo so that it can be downloaded

  2. manually copy the files into the node_modules dir every time

Both of these feel like an unecessary extra step, especially considering what the React-Native docs seem to imply is possible.

I ran into this same issue.

I inspected the node_modules folder for the custom library, and it looks like the custom library was not copied there properly. Instead, it stores a reference to wherever the library is stored on your computer. For me, it was at a different directory. I think that the npm start server was not able to properly handle copying the referenced folder from the node_modules.

For a workaround, I deleted the reference, created a new directory in node_modules with the same name, then copied all files from where the library exists, to that newly created directory in node_modules. Then it worked.

Maybe it has to be moved to the dependency list.

I had a similar error in the project

Moduledateformat does not exist in the Haste module map

and the fix was to explicitly add dateformat as a dependency. Previously it wasn’t and it worked fine.

I’m getting the same error. @Samykills, did you manage to solve it?