tradle/rn-nodeify

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

Closed this issue · 5 comments

jd20 commented

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: facebook/metro#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?

@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?

@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

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

jd20 commented

Submitted PR: #60

closing, resolved by #60