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

Not working with expo and stream #77

Closed kparkov closed 5 years ago

kparkov commented 5 years ago

My dependencies include stream and a handful of other core modules in an Expo project. I've tried a bunch of different strategies, and then someone recommended rn-nodeify.

I have installed the postinstall script:

  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject",
    "postinstall": "rn-nodeify --install --hack"
  },

Yet, after a clean and run npm install (I can confirm it installs the shims), I get this error when I run it with npm start:

undefined is not an object (evaluating 'process.version.slice')

<unknown>
    D:\Development\project\node_modules\stream-browserify\node_modules\readable-stream\lib\_stream_writable.js:57:80
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\node_modules\stream-browserify\node_modules\readable-stream\readable.js:15:28
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\node_modules\stream-browserify\index.js:28:25
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\node_modules\qr-image\lib\qr.js:3:22
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\node_modules\uport-transports\lib\transport\ui\index.js:8:22
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\node_modules\uport-transports\lib\transport\qr.js:14:17
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\node_modules\uport-transports\lib\transport\index.js:8:17
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\node_modules\uport-transports\lib\index.js:8:20
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\node_modules\uport-connect\lib\Connect.js:7070:30
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\node_modules\uport-connect\lib\index.js:34:22
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\lib\uport\index.js:1
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\pages\Introduction.js:7
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\AppNavigator.js:4
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\App.js:2
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
<unknown>
    D:\Development\project\node_modules\expo\AppEntry.js:2
loadModuleImplementation
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:292:12
guardedLoadModule
    D:\Development\project\node_modules\metro\src\lib\polyfills\require.js:179:45
global code
    <unknown file>:0

Am I doing something wrong here? Should Expo (and stream) be supported?

mvayngrib commented 5 years ago

@kparkov r u importing the shim first thing?

i'm not sure if rn-nodeify is compatible with expo, because as far as I know, expo doesn't let you use native modules other than the ones it bundles. Node.js core module shims like for fs (react-native-level-fs), dgram (react-native-udp), net (react-native-tcp), crypto (react-native-crypto) all have native components. You might have to eject first, but check the docs

mvayngrib commented 5 years ago

closing due to inactivity, will reopen if needed

LuisNeves05 commented 2 years ago

Is it compatible yet? I've had problems with Node modules not being compatible with React Native for a week now, but ejecting Expo in order to use rn nodiefy is not an option. Is there any other work around?

thowitz commented 2 years ago

Is it compatible yet? I've had problems with Node modules not being compatible with React Native for a week now, but ejecting Expo in order to use rn nodiefy is not an option. Is there any other work around?

I'm having the same issue, did you ever get it working?

LuisNeves05 commented 2 years ago

Yeah, I did! You can check out my startup’s repo to see our package json. Check NEFTME’s profile to see :)

thowitz @.***> escreveu em sáb., 30/07/2022 às 20:45 :

Is it compatible yet? I've had problems with Node modules not being compatible with React Native for a week now, but ejecting Expo in order to use rn nodiefy is not an option. Is there any other work around?

I'm having the same issue, did you ever get it working?

— Reply to this email directly, view it on GitHub https://github.com/tradle/rn-nodeify/issues/77#issuecomment-1200283721, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALO7WVN22UEHY7PXCFCBZMDVWWA7NANCNFSM4GWPXXCQ . You are receiving this because you commented.Message ID: @.***>

thowitz commented 2 years ago

@LuisNeves05 Thanks for the reply! I managed to fix my current error message (No identifiers allowed directly after numeric literal)

dlrandy commented 2 years ago

@thowitz Hello, same issue here, could you please share the way you fix it ?

thowitz commented 2 years ago

@dlrandy If you comment out all your imports, does the error go away?

Frostswing commented 1 year ago

Yeah, I did! You can check out my startup’s repo to see our package json. Check NEFTME’s profile to see :) thowitz @.> escreveu em sáb., 30/07/2022 às 20:45 : Is it compatible yet? I've had problems with Node modules not being compatible with React Native for a week now, but ejecting Expo in order to use rn nodiefy is not an option. Is there any other work around? I'm having the same issue, did you ever get it working? — Reply to this email directly, view it on GitHub <#77 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALO7WVN22UEHY7PXCFCBZMDVWWA7NANCNFSM4GWPXXCQ . You are receiving this because you commented.Message ID: @.>

Hey, What project is it than? can you send a link? I'm having the same issue, and no solution yet...

Thanks!

LuisNeves05 commented 1 year ago

https://github.com/NEFTME/neftme-poc-dapp

Check it out @Frostswing

Frostswing commented 1 year ago

@LuisNeves05 Thanks!

was your trick using "stream-http" instead the rn-nodify npm? Or was is another thing? Since stream-http didn't do the trick for me :/

thowitz commented 1 year ago

@Frostswing Have you tried the readable-stream package?

Frostswing commented 1 year ago

@thowitz Do you mean linking the stream to the readable-stream package? if so, it doesnt help...

This is my package.json:

 "dependencies": {
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/bottom-tabs": "^6.4.0",
    "@react-navigation/drawer": "^6.5.0",
    "@react-navigation/native": "^6.0.13",
    "airgram": "^5.0.0",
    "assert": "^1.1.1",
    "buffer": "^4.9.1",
    "events": "^1.0.0",
    "expo": "~46.0.9",
    "expo-status-bar": "~1.4.0",
    "firebase": "^9.12.1",
    "i": "^0.3.7",
    "i18next": "^21.9.2",
    "npm": "^9.1.1",
    "path-browserify": "^0.0.0",
    "process": "^0.11.0",
    "react": "18.0.0",
    "react-i18next": "^11.18.6",
    "react-native": "0.69.6",
    "react-native-gesture-handler": "~2.5.0",
    "react-native-level-fs": "^3.0.0",
    "react-native-os": "^1.0.1",
    "react-native-paper": "^4.12.4",
    "react-native-reanimated": "~2.10.0",
    "react-native-safe-area-context": "4.3.1",
    "react-native-screens": "~3.15.0",
    "react-native-vector-icons": "^9.2.0",
    "react-navigation": "^4.4.4",
    "readable-stream": "^1.0.33",
    "rn-nodeify": "^10.3.0",
    "stream-browserify": "^3.0.0",
    "stream-http": "^3.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true,
  "react-native": {
    "os": "react-native-os",
    "path": "path-browserify",
    "fs": "react-native-level-fs",
    "_stream_transform": "readable-stream/transform",
    "_stream_readable": "readable-stream/readable",
    "_stream_writable": "readable-stream/writable",
    "_stream_duplex": "readable-stream/duplex",
    "_stream_passthrough": "readable-stream/passthrough",
    "stream": "readable-stream"
  },
  "browser": {
    "os": "react-native-os",
    "path": "path-browserify",
    "fs": "react-native-level-fs",
    "_stream_transform": "readable-stream/transform",
    "_stream_readable": "readable-stream/readable",
    "_stream_writable": "readable-stream/writable",
    "_stream_duplex": "readable-stream/duplex",
    "_stream_passthrough": "readable-stream/passthrough",
    "stream": "stream-browserify"// changing here to "readable-stream" doesnt help
thowitz commented 1 year ago

@Frostswing Can you try replacing "stream": "stream-readable", with "stream": "stream-browserify", in your package.json?

Frostswing commented 1 year ago

stream-browserify

Same result :(

"dependencies": {
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/bottom-tabs": "^6.4.0",
    "@react-navigation/drawer": "^6.5.0",
    "@react-navigation/native": "^6.0.13",
    "airgram": "^5.0.0",
    "assert": "^1.1.1",
    "buffer": "^4.9.1",
    "events": "^1.0.0",
    "expo": "~46.0.9",
    "expo-status-bar": "~1.4.0",
    "firebase": "^9.12.1",
    "i": "^0.3.7",
    "i18next": "^21.9.2",
    "npm": "^9.1.1",
    "path-browserify": "^0.0.0",
    "process": "^0.11.0",
    "react": "18.0.0",
    "react-i18next": "^11.18.6",
    "react-native": "0.69.6",
    "react-native-gesture-handler": "~2.5.0",
    "react-native-level-fs": "^3.0.0",
    "react-native-os": "^1.0.1",
    "react-native-paper": "^4.12.4",
    "react-native-reanimated": "~2.10.0",
    "react-native-safe-area-context": "4.3.1",
    "react-native-screens": "~3.15.0",
    "react-native-vector-icons": "^9.2.0",
    "react-navigation": "^4.4.4",
    "readable-stream": "^1.0.33",
    "rn-nodeify": "^10.3.0",
    "stream-browserify": "^3.0.0",
    "stream-http": "^3.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true,
  "react-native": {
    "os": "react-native-os",
    "path": "path-browserify",
    "fs": "react-native-level-fs",
    "_stream_transform": "readable-stream/transform",
    "_stream_readable": "readable-stream/readable",
    "_stream_writable": "readable-stream/writable",
    "_stream_duplex": "readable-stream/duplex",
    "_stream_passthrough": "readable-stream/passthrough",
    "stream": "stream-browserify"
  },
  "browser": {
    "os": "react-native-os",
    "path": "path-browserify",
    "fs": "react-native-level-fs",
    "_stream_transform": "readable-stream/transform",
    "_stream_readable": "readable-stream/readable",
    "_stream_writable": "readable-stream/writable",
    "_stream_duplex": "readable-stream/duplex",
    "_stream_passthrough": "readable-stream/passthrough",
    "stream": "stream-browserify"
  }
Frostswing commented 1 year ago

For the stream part i have found a solution to my exact issue here: https://github.com/nodejs/readable-stream/issues/313

Solves specifically the "evaluating 'process.version.slice'" error

But i'm still having issues using Expo and rn-nodify... But its for a different discussion

thowitz commented 1 year ago

@Frostswing Nice one, glad to hear you fixed at least this problem👍Now onto the next one haha