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 asyncstorage-down #61

Closed bitabs closed 6 years ago

bitabs commented 6 years ago

Hi there,

I'm running React Native and one of the module ws is throwing this error:

capture

How can I resolve this?

Thanks

mvayngrib commented 6 years ago

hey @NaseebullahSafi, can you check if you have node_modules/asyncstorage-down, and if not, install it?

bitabs commented 6 years ago

I don't have it. But I thought RN-noteify can do that automatically no? @mvayngrib

bitabs commented 6 years ago

DO I comment it form WS and install it in my node-modules?

mvayngrib commented 6 years ago

looking at the code, i see that it's a peer dependency of react-native-level-fs so it needs to be installed manually in your project (if you need to use fs, which maybe ws does?)

that said, i'm still not sure ws will work in React Native, but you tell me :)

bitabs commented 6 years ago

Hmm, give me a sec, I'll get back to you.

mvayngrib commented 6 years ago

does your package.json have a block that looks like this?

  "react-native": {
    ...
    "http": "react-native-http",
    "https": "https-browserify",

if not, you might need to run rn-nodeify --install --hack (or whatever rn-nodeify command you're running)

keep in mind that any time you install or uninstall a dependency, you need to re-run rn-nodeify

bitabs commented 6 years ago

Ah I see, ok will do that. Thanks, got few more errors, if I can fix them, I'll close the issue. Thanks

mvayngrib commented 6 years ago

can you paste the complete stack?

bitabs commented 6 years ago

I don't know why but the error is gone, and not showing up anymore. It's so weird.

mvayngrib commented 6 years ago

probably you just needed to restart the packager. It caches a lot of things

bitabs commented 6 years ago

Sorry for that, I got it again. Here's the full error: @mvayngrib

capture

And here's my package.json for react-native:

capture
bitabs commented 6 years ago

Ok nevermind that is fixed :)

bitabs commented 6 years ago

@mvayngrib One of my module requires noble. How can I shim this or use rn-nodeify? It doesn't work. Can you please specify the correct order of installing noble. The readme is quite confusing to me. Sorry

mvayngrib commented 6 years ago

@NaseebullahSafi sorry, no idea, this is out of scope of rn-nodeify. Also, idk what platform you're developing for, but I see they don't support Android and iOS.

bitabs commented 6 years ago

Yes I really needed noble for BLE for android. the library (https://github.com/jacobrosenthal/react-native-ble) directed me to here

bitabs commented 6 years ago

@mvayngrib Cant we use any node module in rn-nodeify?

mvayngrib commented 6 years ago

@NaseebullahSafi no, you can use the built-in node modules ('fs', 'crypto', 'dgram' etc.), but any modules that have custom native code (non-Javascript), will not work. You'll need to create your own react-native shims for them, like others have for react-native-udp (dgram), react-native-tcp (net), react-native-crypto (crypto), react-native-ecc (elliptic curve crypto), etc.

bitabs commented 6 years ago

So cant we use rn-nodefiy on this (https://github.com/jacobrosenthal/react-native-ble)? Since they've done it already

mvayngrib commented 6 years ago

according to the author of react-native-ble, you can. I'm just saying rn-nodeify doesn't support arbitrary native modules out of the box. Each module with native components needs its own shim. In this case, rn-nodeify doesn't support noble out of the box, which is why react-native-ble was created. I have never played with react-native-ble myself, so I suggest you follow the instructions on the react-native-ble README and ask the author for help troubleshooting it. Good luck!

bitabs commented 6 years ago

@mvayngrib Sorry for the trouble. It works, cant believe it!!!! :) Thank you so much.

mvayngrib commented 6 years ago

@NaseebullahSafi haha, I'm glad to hear it, and you're welcome :) Good luck with your project!

Philipwzj commented 6 years ago

@NaseebullahSafi How did you fix the asyncstorage-down problem? Thanks!

hzburki commented 5 years ago

I have the same error ... Can anyone explain how to fix this ?

mvayngrib commented 5 years ago

@Philipwzj @hzburki do you have asyncstorage-down installed? If not, install it manually (npm i -S asyncstorage-down) and then re-run your rn-nodeify script.

hzburki commented 5 years ago

@mvayngrib Thank you ... had to install react-native-level-fs as well, then install rn-nodeify on my machine globally and run both the --hack and --install commands. App runs okay now.

But I don't understand why this issue appeared? its a new project only one screen with text on it. I installed react-native-elements and vector-icons. Worked on the folder setup a bit and boom ... couldn't resolve modules.

Is this a bug in NPM ? Whenever you have time can you please explain this in a bit detail. Thanks 😄

mvayngrib commented 5 years ago

@hzburki it's partially the way dependencies work: asyncstorage-down isn't automatically installed because it's a peer dependency of react-native-level-fs, not a direct dependency. Peer dependencies need to be installed explicitly in the top level project, which can be annoying, but on the other hand, it prevents multiple versions of asyncstorage-down from appearing in the dep tree.

...and partially the way the RN packager works:

webpack/browserify/RN packager all have to deal with the same problem: Node.js has core modules (fs, path, process, dgram, net, querystring, crypto, etc.), which don't exist in other native environments (browser, ios javascript engine, android javascript engine). Webpack and browserify have long relied on a set of "shims" supplied by the community: path-browserify, crypto-browserify, browserify-http, etc., and provided ways to set up module resolution to work. The RN project owners and community have so far cared much less about creating a Node.js-like environment in React Native, and thus you have modules like rn-nodeify trying to bridge the gap.

projetsdiy commented 4 years ago

Same problem after install the nodejs ftp package I solved the problem as follow (all commands with sudo on macOS) npm install asyncstorage-down react-native link asyncstorage-down (important) ./node_modules/.bin/rn-nodeify --hack --install cd ios/ pod install react-native run-ios

mvayngrib commented 4 years ago

asyncstorage-down is in peerDependencies, so needs to be installed manually

npm install asyncstorage-down

yes

react-native link asyncstorage-down (important)

absolutely not! asyncstorage-down is a pure JS module, only modules with ios/android native code need react-native link