tradle / rn-nodeify

hack to allow react-native projects to use node core modules, and npm modules that use them
MIT License
615 stars 112 forks source link

Unable to resolve module `constants` from ..node_modules/touch/touch.js #47

Closed TheJoeSchr closed 6 years ago

TheJoeSchr commented 7 years ago

Hi, great project! :)

I'm currently try to get it running with a new expo project. I already install several modules, but now there seems to be a hiccup with "constants".

"<projectpath>\\node_modules\\touch\\touch.js","to":"constants","message":"Unable to resolve module "constants" from "<projectpath>\\node_modules\\touch\\touch.js": Module does not exist in the module map or in these directories (modified to make it readable at github )

I installed it via "postinstall": "rn-nodeify --install fs,buffer,path,util,events,crypto,constants --hack"

I'm on windows. I'm happy to provide any more info to make this work.

Thx

mvayngrib commented 7 years ago

@JoeSchr constants is not a core node module, so I'm not sure why you have it in your postinstall script :)

TheJoeSchr commented 7 years ago

because I saw it in here I figured constants would get handled by rn-nodeify. That's not the case? sadly npm install --save constants is also not working :(

mvayngrib commented 7 years ago

@JoeSchr indeed, my mistake! It's shimmed by constants-browserify. Does constants-browserify get installed when you run npm run postinstall?

TheJoeSchr commented 7 years ago

yes, it got installed, but it seems it won't see it.

I just completely wiped my node_modules, removed constants from postinstall and installed it via simple npm install. now it doesn't find the tls module (another package needs it).

since rn-nodeify isn't supporting tls, I suppose this is the end of the road for me here anyway.

otherwise I could try wiping node_modules again with postinstall constant option enabled, if that helps you?

TheJoeSchr commented 7 years ago

After some testing it seems to me, that rn-nodeify is installing the wrong version of constants-browserify@0.0.1.

Sadly whenever I install the right version constants-browserify@1.0.0 it always gets overwritten after running postinstall.

I can't find where rn-nodeify gets the version number from or where I could change it. Can you point me in the right direction?

I already installed the rn-nodeify version directly from git, because I needed the #21 workaround for streams.

Thx

TheJoeSchr commented 7 years ago

Sry to bother, 1 second after I wrote it, I found it in shims-browserify.js

mvayngrib commented 7 years ago

@JoeSchr small correction: shims.js rather than shims-browserify.js

mvayngrib commented 7 years ago

originally i was experimenting with both webpack and browserify

TheJoeSchr commented 7 years ago

Thx! Now I'm glad I asked

Brucbbro commented 7 years ago

Hello, any update on this? I'm on a similar boat

bundling: UnableToResolveError: Unable to resolve module `constants` from `/Users/username/WebstormProjects/appname/node_modules/anotherpackage/node_modules/touch/touch.js`

I manually edited constants version in shims.js but i still get the same issue. Have u had any luck @JoeSchr ?

TheJoeSchr commented 7 years ago

Hi, I only have a weird workaround. After everything is run and done (also the postinstall script), I run npm i constants-browserify once more. That seems to be the only way to fix it.

I don't know why and I couldn't find anything in the source why rn-nodeify should touch that, but it works for me. But of course every build now takes forever.

To be honest, right now I'm kind of turned off by the whole npm, nodejs, react-native toolset. Everything which should just work (installing dependencies, getting libraries, building, debugging) just takes forever....

mvayngrib commented 7 years ago

@JoeSchr rn-nodeify might be overwriting the version you install with the version specified in shims.js. I agree that it's undesired behavior, so if you want to submit a PR for that, I'd be happy to accept :)

Re: builds taking forever, I haven't experienced that, and I have a project with a ton of dependencies in addition to all the shims. The first build takes a minute or so, but subsequent incremental builds are fast (as long as you don't restart the packager). For reference, I'm on a mid 2014 MacBook Pro.

All in all though, it's kind of a pain to get node.js compatibility on react-native!

TheJoeSchr commented 7 years ago

@mvayngrib No, I isn't overwriting it. I fixed the version number in the shims file like you told me. If you want I can at least submit a PR where I updated the version numbers of constants-browserify?

@ your build time: good to know, that gives me hope once I got in all the dependencies and compatibility. Just now I have to stop the packager, because I have to npm i constants-browserify everytime. So writing stuff takes forever

mvayngrib commented 7 years ago

@JoeSchr sure, submit a PR :) I'll be pushing a few things in a bit too

Brucbbro commented 7 years ago

Thanks! This issue doesn't appear to happen anymore. If it doesn't afflict you either maybe you could close the issue...

On a side note: a module originally written for node and requiring requestmodule is breaking my code, because on RN i think it should use fetch() instead. Do you think a shim could be done to "fix" that? (and what would be a proper place to ask)

Thanks anyways for you effort!!!

TheJoeSchr commented 7 years ago

I still have the issue. Right now, since I tried to decouple the npm package that I want to use and need node core support, even the workaround doesn't work anymore.
I was just too frustrated to further work on it.

mvayngrib commented 7 years ago

@JoeSchr rn-nodeify no longer overwrites installed dep versions without an explicit --overwrite flag

mvayngrib commented 7 years ago

oops, closed by accident

mvayngrib commented 6 years ago

closing, if someone still this issue (and ideally has a stable reproduction), I'd be happy to take a look