parshap / node-libs-react-native

Node core modules for React Native
MIT License
206 stars 60 forks source link

Module "vm" missing. #6

Open kegesch opened 6 years ago

kegesch commented 6 years ago

Nice work with this repo! My app apparently requires "vm", but the "vm-browserify" alias was removed (in c0fb5594049ff96a304671a2dbf57227defebb07). Can you explain why? Is there a specific reason?

parshap commented 6 years ago

vm-browserify uses window.document and dom elements in its implementation, so it won't work in RN. I don't know of a RN-compatible polyfill for vm, but it may be possible to create one. It'd be great if you can contribute one! Or even a "mock" one that stubs out empty functions if that's all you need to get your library working.

kegesch commented 6 years ago

Okay, thank you for the explanation. A mock would propably enough for my usage, but i got it working with adding vm-browserify (i think it is not using the the function at all but just checks if the library is there?) with configuring the rn-cli.config.js like:

'use strict';
const nodelibs = require('node-libs-react-native');
nodelibs.vm  = require.resolve('vm-browserify');

module.exports = {
    extraNodeModules: nodelibs,
};
ka-sh commented 6 years ago

Am having the same issue. @parshap what would be an acceptable solution? a mock or actually using vm-browserify ? if so will create a pull request to cover the VM case

parshap commented 6 years ago

I think a mock is the best solution unless you actually need sandboxing for security. Adding a vm mock to mock/ would be awesome.

toddpi314 commented 6 years ago

note above, you might want to use the resolver syntax:

'use strict';
const nodelibs = require('node-libs-react-native');
nodelibs.vm  = require.resolve('vm-browserify');

module.exports = {
  resolver: {
    extraNodeModules: nodelibs
  },
};

I'm not sure how @Y0nnyy's original snippet would work without that..

PrognosticatorR commented 4 years ago

Can't find variablebtoaafter adding metro.config.js

pcowgill commented 4 years ago

note above, you might want to use the resolver syntax:

Yep, and in addition to using resolver syntax, these days the file would be named metro.config.js rather than rn-cli.config.js