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

Error "require() must have a single string literal argument" when upgrading to RN 0.49 or later #59

Closed jd20 closed 6 years ago

jd20 commented 6 years ago

The dynamic require for 'crypto' that was recently added back to shim.js is now causing issues for newer versions of RN. Recent decision was made with metro-bundler to disallow dynamic requires, long discussion here: https://github.com/facebook/metro/issues/65. Doesn't look like support for dynamic requires will be coming back.

For now, I can work around by commenting out the require('crypto') section (or if crypto was installed, making the require not be dynamic). Any idea for a better solution? Maybe rn-nodeify could rewrite part of the shim.js, based on whether crypto was installed? That seems like it might introduce other issues though. Or maybe we just document this issue in the Readme, and let others manually edit their shim.js as needed?

mvayngrib commented 6 years ago

@jd20 haha, the fun never ends! Let's scrap the pre-emptive require(), and just document it (in react-native-crypto and react-native-randombytes). Let people require('crypto') manually. Are you up for making the changes?

AnthonyLaw commented 6 years ago

@jd20 thank for raise up this issue, i was panic about this issue.

when i implement nem-sdk on my react native project. i have this issue as well.

where should I manually add require('crypto') ?

I have the issue look like this

require() must have a single string literal argument: /Users/Anthony_Law/Documents/Project/nexShimjs/node_modules/nem-sdk/node_modules/ajv/lib/async.js:82

I no understand what related to async modules. But i just wanna use nem-sdk on React native by installed rn-nodeify.

and idea or suggestion?

jd20 commented 6 years ago

@AnthonyLaw In shim.js, you can replace the part which is giving you the error, with just a regular require('crypto').

jd20 commented 6 years ago

Submitted PR: #60

mvayngrib commented 6 years ago

closing, resolved by #60