问题
I started to use Browserify today and it is not working too well so far.
Are there some modules that cannot be Browserified?
I tried searching online for some specifics for a while now but nothing so far.
The main problem I have so far is trying to use the getmac module.
I wouldn't be surprised if accessing such private info from the browser was impossible, but the following link seems to show otherwise.
https://www.npmjs.com/package/getmac
The 2 main errors I got so far is the exec command being undefined after the
exec = require('child_process').exec;
and the platform parameter of the object process being undefined in
isWindows = process.platform.indexOf('win') === 0;
These 2 lines were automatically generated by Browserify. So unless I forgot an include or to install something, it seems like it is just not supported.
I would appreciate any help you might have for me.
回答1:
Browserify only provides browser shims for the node modules listed in the compatibility section of their documentation. If any of the modules you want to use depend on something not listed there (such as child_process), they will not work. There are workarounds for some (such as browserify-fs, which uses a virtual file system in the browser storage), but ultimately you can't bypass any of the normal restrictions a browser has. Browserify doesn't let you run node.js code in the browser, it's just a common-js module system for the browser with some built-in shims.
来源:https://stackoverflow.com/questions/41759020/does-browserify-have-any-limitations