MIDI 的外部要求导致捆绑"process.versions is undefined".js



我试图从justinlatimer浏览node-midi npm模块。我通过npm在我的项目目录中安装了它,然后运行browserify -r midi> bundle.js。我创建了一个简单的html文件,其中包括以下内容:

<script src="bundle.js"></script>
<script>
  var midi = require('midi');
  var input = new midi.input();
  console.log(input.getPortName(0)); // simple test to see if browserified midi works
</script>

这会导致:"TypeError: process。

var fs = require('fs')
  , path = require('path')
  , join = path.join
  , dirname = path.dirname
  , exists = fs.existsSync || path.existsSync
  , defaults = {
    arrow: process.env.NODE_BINDINGS_ARROW || ' → '
    , compiled: process.env.NODE_BINDINGS_COMPILED_DIR || 'compiled'
    , platform: process.platform
    , arch: process.arch
    , version: process.versions.node // RIGHT HERE
    , bindings: 'bindings.node'
    , try: [
      // node-gyp's linked version in the "build" dir
      [ 'module_root', 'build', 'bindings' ]
      // node-waf and gyp_addon (a.k.a node-gyp)
      , [ 'module_root', 'build', 'Debug', 'bindings' ]
      , [ 'module_root', 'build', 'Release', 'bindings' ]
      // Debug files, for development (legacy behavior, remove for node v0.9)
      , [ 'module_root', 'out', 'Debug', 'bindings' ]
      , [ 'module_root', 'Debug', 'bindings' ]
      // Release files, but manually compiled (legacy behavior, remove for node v0.9)
      , [ 'module_root', 'out', 'Release', 'bindings' ]
      , [ 'module_root', 'Release', 'bindings' ]
      // Legacy from node-waf, node <= 0.4.x
      , [ 'module_root', 'build', 'default', 'bindings' ]
      // Production "Release" buildtype binary (meh...)
      , [ 'module_root', 'compiled', 'version', 'platform', 'arch', 'bindings' ]
      ]
}

我认为像process这样的全局变量应该由browserify自动处理。什么好主意吗?

谢谢

在Github上回答:https://github.com/substack/node-browserify/issues/704

从垂直叠加:

" midi模块直接与您的系统硬件接口,因此这可能无法在浏览器中本地工作。"

由于该模块的工作方式,它不能被浏览器化。

最新更新