tradle / rn-nodeify

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

Breakage in resolving invariant and warning. #27

Closed alexwilson closed 6 years ago

alexwilson commented 7 years ago

Running rn-nodeify --install replaces the module definitions used by Facebook's invariant and warning modules, which breaks their resolution.

e.g.

diff -u -r node_modules/invariant/package.json npm_mods/invariant/package.json
--- node_modules/invariant/package.json 2016-12-29 21:03:59.000000000 +0000
+++ npm_mods/invariant/package.json     2016-12-29 21:03:27.000000000 +0000
@@ -23,56 +23,10 @@
     "tap": "^1.4.0"
   },
   "main": "invariant.js",
-  "browser": {
-    "invariant.js": "browser.js",
-    "zlib": "browserify-zlib",
-    "console": "console-browserify",
-    "constants": "constants-browserify",
-    "crypto": "react-native-crypto",
-    "dns": "dns.js",
-    "net": "react-native-tcp",
-    "domain": "domain-browser",
-    "http": "react-native-http",
-    "https": "https-browserify",
-    "os": "os-browserify",
-    "path": "path-browserify",
-    "querystring": "querystring-es3",
-    "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",
-    "dgram": "react-native-udp",
-    "stream": "stream-browserify",
-    "timers": "timers-browserify",
-    "tty": "tty-browserify",
-    "vm": "vm-browserify"
-  },
-  "react-native": {
-    "invariant.js": "browser.js",
-    "zlib": "browserify-zlib",
-    "console": "console-browserify",
-    "constants": "constants-browserify",
-    "crypto": "react-native-crypto",
-    "dns": "dns.js",
-    "net": "react-native-tcp",
-    "domain": "domain-browser",
-    "http": "react-native-http",
-    "https": "https-browserify",
-    "os": "os-browserify",
-    "path": "path-browserify",
-    "querystring": "querystring-es3",
-    "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",
-    "dgram": "react-native-udp",
-    "stream": "stream-browserify",
-    "timers": "timers-browserify",
-    "tty": "tty-browserify",
-    "vm": "vm-browserify"
+  "browser": "browser.js",
+  "browserify": {
+    "transform": [
+      "loose-envify"
+    ]
   }
-}
\ No newline at end of file

I've worked around this here https://github.com/antoligy/react-universal-native-starter/pull/3 by adding an alias to webpack. Any ideas on any better ways of fixing this? Happy to contrib.

mvayngrib commented 7 years ago

interesting, good catch! Right now rn-nodeify edits all package.json files. Ideally, it should ignore at least all of react-native's own deps (and their deps), and possibly have an additional configurable whitelist. You could probably go through react-native's package.json (and all its deps) first to build the default whitelist.

alexwilson commented 7 years ago

Agreed, I was actually about to open another issue addressing this. How would you suggest such a list be implemented (and/or should we be discussing this in a dedicated issue?) - There are some packages, like jwt-simple where I want to use react dependencies (i.e. crypto).

mvayngrib commented 7 years ago

@antoligy I haven't experienced any errors despite rn-nodeify's editing of the invariant and warning modules' package.json's. Do you have an example of a reproducible error? Thanks!

mvayngrib commented 6 years ago

closing due to inactivity, please reopen if the issue persists