Does Browserify have any limitations?

三世轮回 提交于 2019-12-13 06:11:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!