Frage

I am trying to browserify the node-midi npm module from justinlatimer. I installed it via npm in my project directory, then ran browserify -r midi > bundle.js. I created a bare bones html file that includes the following:

<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>

This results in: "TypeError: process.versions is undefined" at 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' ]
      ]
}

I thought globals like process were supposed to be handled automatically by browserify. Any ideas?

Thank you

War es hilfreich?

Lösung

Answered on Github: https://github.com/substack/node-browserify/issues/704

From Substack:

"The midi module interfaces directly with your system hardware so this can't possibly work natively in the browser."

Because of the way the module works, it can't be browserified.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top