GithubHelp home page GithubHelp logo

tradle / rn-nodeify Goto Github PK

View Code? Open in Web Editor NEW
611.0 8.0 113.0 96 KB

hack to allow react-native projects to use node core modules, and npm modules that use them

License: MIT License

JavaScript 100.00%

rn-nodeify's People

Contributors

aprock avatar badver avatar brysgo avatar dcousens avatar fubinator avatar gabceb avatar jd20 avatar johnnytomcat avatar laurion avatar mamamama-su-da avatar mcarter00 avatar mhofman avatar mistersourcerer avatar mvayngrib avatar secretmapper avatar staltz avatar thejoeschr avatar vespakoen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rn-nodeify's Issues

Add support for typed arrays

I didn't see a mention of typed arrays in the shims. For a react-native project I'm working on I added
support for the polyfills from typedarray to the shims.js file generated by rn-nodeify.

This fixed an error I got importing blake2b

TypeError: main.startsWith is not a function

Got this error today:

rn-nodeify --install buffer,process,console,stream,vm,events,path --hack

not overwriting "buffer"
not overwriting "process"
not overwriting "console-browserify"
not overwriting "stream-browserify"
not overwriting "vm-browserify"
not overwriting "events"
not overwriting "path-browserify"
not overwriting "readable-stream"
not overwriting shim.js. For the latest version, see rn-nodeify/shim.js
removing browser exclude node_modules/htmlparser2/package.json readable-stream
normalized "main" browser mapping in immediate, fixed here: https://github.com/facebook/metro-bundler/pull/3
normalized "main" browser mapping in lie, fixed here: https://github.com/facebook/metro-bundler/pull/3
normalized "main" browser mapping in pouchdb-find, fixed here: https://github.com/facebook/metro-bundler/pull/3
removing browser exclude node_modules/tweetnacl/package.json buffer
normalized "main" browser mapping in readable-stream, fixed here: https://github.com/facebook/metro-bundler/pull/3
normalized "main" browser mapping in readable-stream, fixed here: https://github.com/facebook/metro-bundler/pull/3
normalized "main" browser mapping in readable-stream, fixed here: https://github.com/facebook/metro-bundler/pull/3
normalized "main" browser mapping in readable-stream, fixed here: https://github.com/facebook/metro-bundler/pull/3
removing browser exclude node_modules/sqlite3/node_modules/tweetnacl/package.json buffer
normalized "main" browser mapping in readable-stream, fixed here: https://github.com/facebook/metro-bundler/pull/3
/usr/local/lib/node_modules/rn-nodeify/cmd.js:327
      const alt = main.startsWith('./') ? main.slice(2) : './' + main
                       ^

TypeError: main.startsWith is not a function
    at /usr/local/lib/node_modules/rn-nodeify/cmd.js:327:24
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)

Any suggestions?

please update npm

The buffer package in npm is outdated. [email protected] does not have Buffer.alloc function.

After using the latest version of buffer, I'm able to use webtorrent now.

rn-nodeify doesn't work for android anymore(?)

This issue was probably filed in the wrong place. The essence is:

To reproduce, just run react-native init projectName, add shim.js to the projectrun rn-nodeify --install, and then in index.android.js add require('./shim'); to the top of the file. Running cd android && ./gradlew assembleRelease will break or hang on bundleReleaseJsAndAssets.

Unable to resolve module `crypto` from `../node_modules/sjcl/sjcl.js`

I keep getting this error after trying to run the app:

Unable to resolve module `crypto` from `../node_modules/sjcl/sjcl.js`: Module does not exist in the module map

Here's my postinstall script:
rn-nodeify --install buffer,events,react-native-crypto,react-native-randombytes,stream,util,vm --hack

And here are the react-native and browser fields:

"react-native": {
  "_stream_duplex": "readable-stream/duplex",
  "_stream_passthrough": "readable-stream/passthrough",
  "_stream_readable": "readable-stream/readable",
  "_stream_transform": "readable-stream/transform",
  "_stream_writable": "readable-stream/writable",
  "crypto": "react-native-crypto",
  "stream": "stream-browserify",
  "vm": "vm-browserify"
},
"browser": {
  "_stream_duplex": "readable-stream/duplex",
  "_stream_passthrough": "readable-stream/passthrough",
  "_stream_readable": "readable-stream/readable",
  "_stream_transform": "readable-stream/transform",
  "_stream_writable": "readable-stream/writable",
  "crypto": "react-native-crypto",
  "stream": "stream-browserify",
  "vm": "vm-browserify"
}

Here's the shim.js generated:

if (typeof __dirname === 'undefined') global.__dirname = '/'
if (typeof __filename === 'undefined') global.__filename = ''
if (typeof process === 'undefined') {
  global.process = require('process')
} else {
  var bProcess = require('process')
  for (var p in bProcess) {
    if (!(p in process)) {
      process[p] = bProcess[p]
    }
  }
}

process.browser = false
if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer

// global.location = global.location || { port: 80 }
var isDev = typeof __DEV__ === 'boolean' && __DEV__
process.env['NODE_ENV'] = isDev ? 'development' : 'production'
if (typeof localStorage !== 'undefined') {
  localStorage.debug = isDev ? '*' : ''
}

It might also be worth noting that the "crypto": "react-native-crypto" entries on the react-native & browser fields on package.json weren't generated automatically. I had to manually add them.

The weird thing is that it worked a couple of times (twice, to be exact). But when my modules changed and I had to npm install again it just won't run anymore. I wonder what's wrong. Any help would be appreciated!

rn-nodeify version: 7.0.1
npm version: 5.3.0
react-native version: 0.46.3

Add changelog / releases / tags

Have you considered adding documentation for releases? Right now I can't seem to find any details regarding what has changed (I'm aware I could look at the commits, but that's a bit cumbersome). Would you be open to adding a CHANGELOG.md file or changing the publish process to describe updates on Github releases?

fs.readFile callback not called with react-native 0.20.0

First, thanks for making most node core modules work on react-native!

I found that fs.readFile() didn't work well with react-native + rn-nodeify. I cloned the example project, and tries to run fs code on it with no luck.

Shell script to reproduce the issue:

#!/bin/bash
git clone https://github.com/mvayngrib/adexample.git
cd adexample
sed -i '' 's/"react-native": "^0.18.0-rc",/"react-native": "^0.20.0",/g' package.json
cat > fstest.js <<FsTestingCode
var fs = require('fs');
fs.mkdir('/home', function() {
    console.log('mkdir');
    fs.writeFile('/home/hello-world.txt', 'Hello world!\n', function() {
        console.log('writeFile');
        fs.readFile('/home/hello-world.txt', 'utf-8', function(err, data) {
            console.log('readFile');
            console.log(data);
        });
    });
});
FsTestingCode
sed -i '' 's/asyncstorage-down\/test\/test/.\/fstest.js/g' index.ios.js
echo "console.time = console.log;" >> index.ios.js
echo "console.timeEnd = console.log;" >> index.ios.js
npm install
open ios/adexample.xcodeproj

From the output I can tell mkdir and writeFile worked, however the readFile callback is not called at all. Also the app hangs with 100% CPU usage and consumes more and more memory.

fs_readfile

The same code running with react-native 0.18.0-rc did call the readFile callback, but "data" is empty string instead of the expected file content.

Please bump -crypto and -randombytes deps

react-native-crypto and react-native-randombytes are both at 2.x.x now (adding Android support in the latter) but rn-nodeify downgrades them to 1.x.x. Please update the dependencies!

Require statements in shim.js are not being evaluated conditionally

There are several require's in shim.js, that are supposed to only evaluate if react-native-crypto is in the package.json's dependencies. However, for me on RN 0.48.2, these require statements act like 'import', and are evaluated statically not dynamically, giving errors like "Unable to resolve module 'browserify-sign/algos' if react-native-crypto is not installed.

How can I undo --install

I want to remove the modules I installed with nodeify and remove them from package.json, is there an easy way for that?

BufferUtil is undefined: bitcore lib

@mvayngrib I am having trouble "nodeifying" the bitcore library.

You can check out the source code @ https://github.com/SeanAvery/react-native-eth-wallet

After running with --hack --install I am getting an error: BufferUtil.isBuffer is not a function

This makes sense, because the the object does not contain a isBuffer function
screen shot 2017-04-05 at 11 56 48 am

I have tried following the hack described here bitpay/bitcore-lib#108
Also, npm installed buffer and ran rn-nodeify again

The buffer object looks good as such:

screen shot 2017-04-05 at 11 53 35 am

However, I am getting this strange error: Requiring module "21", which threw an exception.

This is seems to be the line where I require buffer...

Is there anything else I can try out?
Thank you!

Streams not working

I need to use this SDK: https://github.com/BitGo/BitGoJS with a react native app. My idea was to use your package to replace node core dependencies like streams and buffers with their client counterparts so the SDK could run on react native. I've cloned that repo, ran rn-nodeify --install --hack, required shim.js at index.js and imported that index.js from a module in my app. But when I try to run it on a device I get error:

Object prototype may only be an Object or null.
inherits
inherits_browser.js:5
<unknown>
_stream_readable.js:52
...

As you can see it's unable to inherit readable stream from stream. If I add console.log to _stream_readable.js I see that after it does var Stream = require('stream') variable Stream holds an empty object {} and it's prototype is undefined so it fails to inherit.
How can I fix this behavior and what is its reason?

rn-nodeify is breaking VSCode's debug feature

Hello,

Apparently rn-nodeify is breaking the bridge between Visual Studio Code's React Native extension and the bundler.

The debugger worker tries to call process.send, but the following error is thrown:

Starting debugger app worker.
Established a connection with the Proxy (Packager) to the React Native application
Debugger worker loaded runtime on port 34436
TypeError: process.send is not a function
debuggerWorker.js:40
    at postMessage ([PROJECT_WORKSPACE_ROOT]/.vscode/.react/debuggerWorker.js:40:13)
    at sendReply ([PROJECT_WORKSPACE_ROOT]/.vscode/.react/debuggerWorker.js:113:7)
    at executeApplicationScript ([PROJECT_WORKSPACE_ROOT]/.vscode/.react/debuggerWorker.js:98:7)
    at [PROJECT_WORKSPACE_ROOT]/.vscode/.react/debuggerWorker.js:119:7
    at process.<anonymous> ([PROJECT_WORKSPACE_ROOT]/.vscode/.react/debuggerWorker.js:35:9)
    at emitTwo (events.js:126:13)
    at process.emit (events.js:214:7)
    at emit (internal/child_process.js:772:12)
    at _combinedTickCallback (internal/process/next_tick.js:141:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

More information and related issue on VSCode's repo: microsoft/vscode-react-native#606

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

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?

Do not work on windows

node 8.5
npm 5.6.0
windows 10

for modules like vm, stream - it says
Unable to resolve module vm from path to nested node library: Module does not exist in the module map.
If I require vm directly from my code - it works, but if require from some child library it says like message above. Seems react-native flag in package.json do not work properly for windows.
On mac all works fine.

If I add rn-cli.config like suggested here

module.exports = {
  extraNodeModules: require('node-libs-browser'),
};

https://gist.github.com/parshap/e3063d9bf6058041b34b26b7166fd6bd - it starts working

Does stream work yet?

Hey, thanks for this package!

I am trying to make my library work in react-native (using react-native's packager)
I have been shimming stuff myself, and then found this package that does it for me, great!

The error I get is:
"Requiring unknown module "stream". If you are sure the module is there, try restarting the packager."

This is my dependency graph
mypackage -> levelup -> level-iterator-stream -> readable-stream -> ./lib/_stream_readable.js -> stream

It looks like rn-nodify is shimming all of stream's dependencies, but not the stream package itself.

Is this an edge case?

Besides that, out of interest, I noticed that you do a === null check here: https://github.com/facebook/react-native/blob/9a918ef48fb943a9dcc1885a6cf09ca0f510c695/packager/react-packager/src/DependencyResolver/Package.js#L94-L98

Does the react-native field get populated with a null value somewhere else?
Otherwise, what happens if react-native is not present in a package.json (undefined)?

Update package.json "react-native" field instead of "browser"

As react-native has added support of "react-native" field to package.json, maybe this package can modify that field instead of browser?

I'm trying to build an app have share code based between web app, electron and react-native app, limit the hacks on react-native seems proper.

How does this work?

Can you give a rundown of what happens when you run rn-nodeify? I understand it changes your top-level package.json, but what is actually using the browser and react-native keys? And it seems to make changes to files inside node_modules/ as well?

Undefined Buffer

For some weird reason I get a can't find variable/undefined variable Buffer error.

It seems like Buffer is used by most modules as a global (without a require). In the shim.js file, I do see that buffer is being defined in the global scope:

if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer

But I still get the error as if Buffer isn't being defined and I'm stumped. Even went as far as to apply hacks to replace Buffer with require('buffer'), but realized it to be a futile exercise (too many files requiring it and the regex would be too complex to handle all edge cases).

Is there something I'm missing or is Buffer somehow not working right now?

not supported by this browser

hi,
thanks for your repo. I want to use bitcoinjs-lib in my reactnative project, so i use your repo, when i call ECPair.makeRandom method in android, a Warning massage display.
screenshot_2017-12-30-19-59-39

When I was Debug JS Remotely in chrome, there is no such problem.

Breakage in resolving invariant and warning.

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 alexwilson/react-universal-native-starter#3 by adding an alias to webpack.
Any ideas on any better ways of fixing this? Happy to contrib.

Take "browserify" field into consideration

https://github.com/mvayngrib/rn-nodeify/blob/bac7668c00666cb9704b8fd871633d938487d6f8/cmd.js#L211

Should look something like:

var orgBrowser = pkgJson.browser || pkgJson.browserify || {};

Some packages are still relying on the browserify field, "shoe" for example:

https://github.com/substack/shoe/blob/5b6edae990ac5919dd78d966a4b99b05b69f6554/package.json#L6

If rn-nodeify would consider the "browserify" field, the correct mappings will end up in the "browser" field and the react-native package will accept it happily.

Error on new RN 0.45.1

After run ./node_modules/.bin/rn-nodeify --hack --install

.....
......
installing from npm readable-stream
installing: npm install --save tradle/react-native-http#834492d [email protected]
npm WARN gentlyRm not removing /Users/anhtai/Develop/RNApp01/node_modules/.bin/jest as it wasn't installed by /Users/anhtai/Develop/RNApp01/node_modules/jest-cli
npm WARN [email protected] requires a peer of asyncstorage-down@^3.0.0 but none was installed.

+ [email protected]
+ [email protected]
added 2 packages, removed 686 packages and updated 61 packages in 38.5s
/Users/anhtai/Develop/RNApp01/node_modules/rn-nodeify/cmd.js:66
      if (err) throw err
               ^

Error: ENOENT: no such file or directory, open '/Users/anhtai/Develop/RNApp01/node_modules/rn-nodeify/shim.js'

And because of it remove almost module, so react-native project can't run anymore.

Seems broken on Windows ..?

C:\src\app>npm run build:crypto-shim

[email protected] build:crypto-shim C:\src\app
node ./node_modules/.bin/rn-nodeify --hack --install

C:\src\app\node_modules.bin\rn-nodeify:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3

undefined is not an object (evaluating 'RNRandomBytes.seed')

  • npm install rn-nodeify -g
  • npm install braintree --save
  • rn-nodeify --install "http,events,url,stream,buffer,https,crypto,vm" --hack
  • clone react-native node in package.json as braintree

Getting undefined is not an object (evaluating 'RNRandomBytes.seed') error in the var braintree = require("braintree");

Seems that it is failing somewhere in crypto. Any clues what the error may be and how to resolve it?

It's not clear how to use this

I'm trying to use this package, to use mocha for unit testing in React Native, but I'm not having any luck.

After running npm install -g rn-nodeify, I tried running rn-nodeify, with no parameters, on the main project folder before running npm install mocha. I also tried rn-nodeify node_modules/mocha. I added require('mocha') in my index.ios.js and it fails with the same error as if I hadn't run the rn-nodeify command. I'm just not sure if I'm using this right, or if there's something else I should do.

Could you write up instructions in the readme file, with an example of using rn-nodeify to load a node module in a React Native app?

process.browsfy = true

hi mvayngrib
in rn 0.46.4, shim.js didnot play its role. In node_module, process.browsfy print true.

Running rn-nodeify breaks node_modules

After running ./node_modules/.bin/rn-nodeify --install --hack it does some weird thing to my react-native dep (turns the folder under node_modules into a bunch of empty folders):
screen shot 2017-07-05 at 10 41 45 am
I thought it was something with yarn, but no, if I don't run rn-nodeify it's ok. Why? How can I fix?

Can't resolve net?

Hello! First of all again, awesome work with rn-nodeify... hope an official react-native solution gets implemented soon.

Anyway, when I try rn-nodeify, I get a redbox errror say net can't be resolved, and @tradle/utp was unable to be found. I already tried rm -rf-ing my node_modules folder and clearing my cache but I always get the same error.

Unable to resolve module `constants` from ..node_modules/touch/touch.js

Hi,
great project! :)

I'm currently try to get it running with a new expo project. I already install several modules, but now there seems to be a hiccup with "constants".

"<projectpath>\\node_modules\\touch\\touch.js","to":"constants","message":"Unable to resolve module "constants" from "<projectpath>\\node_modules\\touch\\touch.js": Module does not exist in the module map or in these directories
(modified to make it readable at github )

I installed it via
"postinstall": "rn-nodeify --install fs,buffer,path,util,events,crypto,constants --hack"

I'm on windows. I'm happy to provide any more info to make this work.

Thx

problem using crypto + randombytes

Hi there,

Thanks for the great repos.
I am using your solution to run node core modules on a react native app, and this is my postinstall script
./node_modules/.bin/rn-nodeify --install --hack "crypto,stream,process,vm,process,buffer,url,assert,events,querystring"

and my shim looks like this:

if (typeof __filename === 'undefined') global.__filename = ''
if (typeof process === 'undefined') {
  global.process = require('process')
} else {
  const bProcess = require('process')
  for (var p in bProcess) {
    if (!(p in process)) {
      process[p] = bProcess[p]
    }
  }
}

process.browser = false
if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer

// global.location = global.location || { port: 80 }
const isDev = typeof __DEV__ === 'boolean' && __DEV__
process.env['NODE_ENV'] = isDev ? 'development' : 'production'
if (typeof localStorage !== 'undefined') {
  localStorage.debug = isDev ? '*' : ''
}

And on my app, I have a call to eth-lib, which calls this func:

var random = function random(bytes) {
  var rnd = void 0;
  if (typeof window !== "undefined" && window.crypto && window.crypto.getRandomValues) rnd = window.crypto.getRandomValues(new Uint8Array(bytes));else if (typeof require !== "undefined") rnd = require("c" + "rypto").randomBytes(bytes);else throw "Safe random numbers not available.";
  var hex = "0x";
  for (var i = 0; i < bytes; ++i) {
    hex += ("00" + rnd[i].toString(16)).slice(-2);
  }return hex;
};

which returns to me
'''typeerror undefined is not an object rnd[i]'''

Any idea what may be causing this? FYI, If I turn debug mode on, it works as expected since the window object must be available.

iOS, ANDROID - RELEASE - Error: Secure random number generation is not supported by this browser.

For iOS release scheme, problem with bip39.generateMnemonic from bip39 package after nodeify:

Secure random number generation is not supported by this browser.
Use Chrome, Firefox or Internet Explorer 11

Works fine for iOS debug.
Works fine for Android debug and release.

React-Native version: "0.56.0-rc"

I am up-to-date with all packages and installation flow:

"rn-nodeify": "10.0.0"
"react-native-crypto": "2.1.2"
"react-native-randombytes": "3.4.0"

My shim.js:

if (typeof __dirname === 'undefined') global.__dirname = '/'
if (typeof __filename === 'undefined') global.__filename = ''
if (typeof process === 'undefined') {
  global.process = require('process')
} else {
  const bProcess = require('process')
  for (const p in bProcess) {
    if (!(p in process)) {
      process[p] = bProcess[p]
    }
  }
}

process.browser = false
if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer

// global.location = global.location || { port: 80 }
const isDev = typeof __DEV__ === 'boolean' && __DEV__
process.env['NODE_ENV'] = isDev ? 'development' : 'production'
if (typeof localStorage !== 'undefined') {
  localStorage.debug = isDev ? '*' : ''
}

// If using the crypto shim, uncomment the following line to ensure
// crypto is loaded first, so it can populate global.crypto
require('crypto')

My index.js of the app start with import './shim.js'

I was also trying with below shim.js file but no success on iOS release:

if (typeof __dirname === 'undefined') global.__dirname = '/'
if (typeof __filename === 'undefined') global.__filename = ''
if (typeof process === 'undefined') {
  global.process = require('process')
} else {
  const bProcess = require('process')
  for (var p in bProcess) {
    if (!(p in process)) {
      process[p] = bProcess[p]
    }
  }
}

process.browser = false
if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer

// global.location = global.location || { port: 80 }
const isDev = typeof __DEV__ === 'boolean' && __DEV__
process.env['NODE_ENV'] = isDev ? 'development' : 'production'
if (typeof localStorage !== 'undefined') {
  localStorage.debug = isDev ? '*' : ''
}

if (require('./package.json').dependencies['react-native-crypto']) {
  // important that this comes before require('crypto')
  const algos = require('browserify-sign/algos')
  if (!algos.sha256) {
    algos.sha256 = {
      "sign": "ecdsa",
      "hash": "sha256",
      "id": new Buffer("")
    }
  }

  let crypto
  if (typeof window === 'object') {
    if (!window.crypto) window.crypto = {}
    crypto = window.crypto
  } else {
    crypto = require('crypto')
  }

  if (!crypto.getRandomValues) {
    crypto.getRandomValues = getRandomValues
  }

  let randomBytes

  function getRandomValues (arr) {
    if (!randomBytes) randomBytes = require('react-native-randombytes').randomBytes

    const bytes = randomBytes(arr.length)
    for (var i = 0; i < bytes.length; i++) {
      arr[i] = bytes[i]
    }
  }
}

http module breaks

hi @mvayngrib

Currently i am experiencing a problem. Normally nodeifying was working pretty good, but however after the latest web3-core update, (web3.js 1.0.0-beta.35, see breaking change: The HTTP provider now accepts an options object, instead of timeout and headers parameters:) this line fails on xhr2-cookies:

if (this.withCredentials && (response.headers['set-cookie'] || response.headers['set-cookie2'])) {
  XMLHttpRequest.cookieJar.setCookies(response.headers['set-cookie'] || response.headers['set-cookie2']);
}

and throws Cannot read property 'set-cookie' of undefined.

If I do comment out response.headers['set-cookie'] parts from the node module xhr2-cookies, i do get a ssl error when i try to connect to ethereum rpc node. So this cookie is normally using browser cache I think, whereas we dont have a substitude for that from rn-nodeify. Is this assumption correct, what do you think?

Cheers

Error: Secure random number generation is not supported by this browser. Use Chrome, Firefox or Internet Explorer 11

When I use bip39,run var mnemonic =bip39.generateMnemonic(); Errors such as Title.

My package.json

{
  "name": "Demo",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "postinstall": "./scripts/postinstall.sh",
    "test": "jest"
  },
  "dependencies": {
    "assert": "^1.4.1",
    "bip39": "^2.5.0",
    "events": "^1.1.1",
    "react": "16.3.1",
    "react-native": "0.55.4",
    "react-native-crypto": "^2.1.2",
    "react-native-randombytes": "^3.1.0",
    "readable-stream": "^1.0.33",
    "stream-browserify": "^1.0.0",
    "unorm": "^1.4.1",
    "vm-browserify": "0.0.4"
  },
  "devDependencies": {
    "babel-jest": "22.4.3",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.4.3",
    "react-test-renderer": "16.3.1",
    "rn-nodeify": "^10.0.0"
  },
  "jest": {
    "preset": "react-native"
  },
  "react-native": {
    "crypto": "react-native-crypto",
    "_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",
    "vm": "vm-browserify"
  },
  "browser": {
    "crypto": "react-native-crypto",
    "_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",
    "vm": "vm-browserify"
  }
}

postinstall.sh:
./node_modules/.bin/rn-nodeify --hack --install "assert, crypto, stream, events, vm"

andimport './shim'; also in the index.js

What configuration do I lack?

process.version.slice - undefined is not an object

i tried to installed stream:
rn-nodeify --install stream --hack

the bundle gets created but ... i get the error in the title from:
node_modules/readable-stream/lib/_stream_writable.js 57:80

any idea how to bypass this? :)

thanks

randombytes not supported

I'm having trouble getting rn-nodeify to work with randombytes.

The read me says nodeify doesn't work with linked modules, so does that mean I can't use react-native-randombytes?

When I try to use a module that uses randombytes I get an error that secure number generation is not supported.

`inherits` package doesn't work, but it used to before

When trying to run android, I'm getting Object prototype may only be an Ojbect or null on the inherits package (inherits_browser.js:5)

Note that this is the inherits package that is inside util. E.g. the complete path of the file throwing the exception is .../my_app/node_modules/util/node_modules/inherits/inherits_browser.js

I ran rn-nodeify --install --hack to no avail.

My rn-nodeify version is 10.0.0.

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.