Open kegesch opened 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.
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,
};
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
I think a mock is the best solution unless you actually need sandboxing for security. Adding a vm
mock to mock/
would be awesome.
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..
Can't find variablebtoa
after adding metro.config.js
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
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?