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

Module react does not exist in the Haste module map. for library with only JS(react) code #65

Open
Samykills opened this issue Jun 13, 2018 · 20 comments

Comments

@Samykills
Copy link

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 :(

@maicki
Copy link
Contributor

maicki commented Jun 15, 2018

@Samykills how do you link the library? You should reference the library within the package.json in your main app and install it via npm install. It seems currently it tries to use library from the Desktop and not from the node_modules folder.

@petgru
Copy link

petgru commented Aug 8, 2018

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

@thorbenprimke
Copy link
Collaborator

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.

@thorbenprimke
Copy link
Collaborator

@maicki ^^^ that's the error I was talking about earlier.

@maicki
Copy link
Contributor

maicki commented Aug 29, 2018

@thorbenprimke Did you add dateformat to the dependency list of the library or the app you use the lib?

@thorbenprimke
Copy link
Collaborator

thorbenprimke commented Aug 29, 2018 via email

@Samykills
Copy link
Author

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

@sovanndyul
Copy link

fixed by npm add @babel/runtime

@menrobaer
Copy link

menrobaer commented Oct 3, 2018

Add this command to your terminal >_
npm add @babel/runtime

Problem solved!

@akshayjai1
Copy link

What happened with me for this problem,

I encountered this problem twice,

  1. first time i mistakenly imported a js package when it was not installed, it resolved by removing that mistaken import statement

  2. second time i was trying to install 'react-native-modal-overlay' package, and instead of using npm install, i used yarn add react-native-modal-overlay, tried all steps i could find on net, but not resolved, finally, I took a fresh install of repository in another package, -----then also the build failed, t

-- then i ran npm cache clean, ( the result asked to run command 'npm install --cache /tmp/empty-cache'
-- i ran this command, and then tried to make build it succeeded

@kumarkundan
Copy link

Delete your node_module and run npm install

@yuanzhanghu
Copy link

yuanzhanghu commented Oct 31, 2018

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

@evanjmg
Copy link

evanjmg commented Nov 28, 2018

as of today, I still have to npm i the package remotely; npm link only works for the native code - once the build completes the javascript doesn't work - I get this error

@maicki
Copy link
Contributor

maicki commented Nov 28, 2018

@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

@miguelHx
Copy link

miguelHx commented Dec 3, 2018

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.

@techieyann
Copy link

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.

@CyrusZei
Copy link

CyrusZei commented Mar 2, 2019

what worked for me was to check at the top of your file so that it does not imported something like

import { threadId } from 'worker_threads';

Remove that and it works

@Jerrywyx
Copy link

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.

Thank you, I think you are correct about the React-Native's doc, npm install really has nothing to do with making npm package to be locally available.

@aadilmehrajbhat
Copy link

If nothing work try to update dependencies in package.json as

"dependencies": {
     "react": "16.3.1",
     "react-native": "0.55.4"
     ...
}

@jonathanconway
Copy link

Yep it looks like symlinks are the issue. Having the same problem with importing sibling modules within a Yarn Workspaces mono-repo. I think the solution for now will be to use watchman to manually copy over the sibling module to the consumer's node_modules folder on every change.

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

No branches or pull requests