tradle / rn-nodeify

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

shim.js issue on IOS #116

Open rares-lupascu opened 2 years ago

rares-lupascu commented 2 years ago

i do not know if i am the only one having this issue but ... this line in shim.js

process.env['NODE_ENV'] = isDev ? 'development' : 'production';

has to changed into this

env = process.env ?? {};
env['NODE_ENV'] = isDev ? 'development' : 'production';
process.env = env;

to fix this error on iOS

error shim.js: /Users/wowzaaa/Projects/ideomaker/radixstream/shim.js: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "StringLiteral".
TypeError: /Users/wowzaaa/Projects/ideomaker/radixstream/shim.js: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "StringLiteral"
    at Object.validate (/Users/wowzaaa/Projects/ideomaker/radixstream/node_modules/@babel/types/lib/definitions/utils.js:131:11)
    at validateField (/Users/wowzaaa/Projects/ideomaker/radixstream/node_modules/@babel/types/lib/validators/validate.js:24:9)
    at validate (/Users/wowzaaa/Projects/ideomaker/radixstream/node_modules/@babel/types/lib/validators/validate.js:17:3)
    at NodePath._replaceWith (/Users/wowzaaa/Projects/ideomaker/radixstream/node_modules/@babel/traverse/lib/path/replacement.js:170:5)
    at NodePath.replaceWith (/Users/wowzaaa/Projects/ideomaker/radixstream/node_modules/@babel/traverse/lib/path/replacement.js:152:8)
    at PluginPass.MemberExpression (/Users/wowzaaa/Projects/ideomaker/radixstream/node_modules/react-native-dotenv/index.js:122:16)
    at newFn (/Users/wowzaaa/Projects/ideomaker/radixstream/node_modules/@babel/traverse/lib/visitors.js:177:21)
    at NodePath._call (/Users/wowzaaa/Projects/ideomaker/radixstream/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/Users/wowzaaa/Projects/ideomaker/radixstream/node_modules/@babel/traverse/lib/path/context.js:40:17)
info Run CLI with --verbose flag for more details.
Command PhaseScriptExecution failed with a nonzero exit code

if anyone has another fix for this i would love to hear about it :)

thanks

DDushkin commented 2 years ago

I also had such error

Execution failed for task ':app:bundleReleaseJsAndAssets'.
Process 'command 'node'' finished with non-zero exit value 1

on creating android APK with./gradlew assembleRelease

Then I tried to run npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

and it showed me more detailed error

error shim.js: /coinweb-app/shim.js: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "StringLiteral".

And in the end I was able to fix it like this

const isDev = typeof __DEV__ === "boolean" && __DEV__;
Object.assign(process.env, { NODE_ENV: isDev ? "development" : "production" });

So I agree there is a problem with

process.env['NODE_ENV'] = isDev ? 'development' : 'production';
fifa-master commented 11 months ago

@DDushkin Thank you man!!! You saved my day