midi的外部需求导致bundle.js中的“process.versions未定义”

时间:2014-03-25 16:26:22

标签: javascript node.js browserify

我正在尝试从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>

这会导致:&#34; TypeError:process.versions未定义&#34;在bundle.js 90:

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' ]
      ]
}

我认为像进程一样的全局变量应该由browserify自动处理。有什么想法吗?

谢谢

1 个答案:

答案 0 :(得分:0)

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

来自Substack:

&#34; midi模块直接与您的系统硬件连接,因此无法在浏览器中本地工作。&#34;

由于模块的工作方式,它无法进行浏览化。