Allen Allen - 1 year ago 87
Node.js Question

node-webkit: calls to require() throw "AssertionError: missing path"

I'm writing a node-webkit application (based on node-webkit-hipster-seed) and I'm trying to import additional node modules. I've found that even if I attempt to import default node modules (such as

) I get the following error:

var http = require('http');
AssertionError: missing path

with the stack trace:

"AssertionError: missing path
at Module.require (module.js:359:3)
at require (module.js:376:17)
at window.require (eval at undefined, <anonymous>:1:112)
at _require (file:///Users/...project/_public/js/vendor.js:92:38)
at require (file:///Users/...project/_public/js/vendor.js:162:16)
at eval (eval at undefined, <anonymous>:2:6)
at Object.InjectedScript._evaluateOn (eval at undefined, <anonymous>:603:39)
at Object.InjectedScript._evaluateAndWrap (eval at undefined, <anonymous>:562:52)
at Object.InjectedScript.evaluate (eval at undefined, <anonymous>:481:21)"

I'm not sure what's going on. Is something mangling
that I don't know about? Is this
not the CommonJS require?

Answer Source

It turns out that the issue was that I also had ace.js loaded, which also assigns a global require function.

To solve this, you can add the following code snippet: (source)

<script type="text/javascript">
    window.requireNode = window.require;
    window.require = undefined; 

in the head of your main html file. Then just use requireNode instead of require.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download