【问题标题】:node-webkit: calls to require() throw "AssertionError: missing path"node-webkit:调用 require() 抛出“AssertionError:缺少路径”
【发布时间】:2014-07-19 23:44:24
【问题描述】:

我正在编写一个 node-webkit 应用程序(基于 node-webkit-hipster-seed)并且我正在尝试导入其他节点模块。我发现即使我尝试导入默认节点模块(例如fshttp),我也会收到以下错误:

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

堆栈跟踪:

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

我不确定发生了什么。有什么我不知道的东西在破坏require 吗?这 require 不是 CommonJS 要求的吗?

【问题讨论】:

    标签: node.js webkit node-webkit assertions


    【解决方案1】:

    事实证明,问题在于我还加载了ace.js,它还分配了一个全局require 函数。

    要解决这个问题,可以添加以下代码sn -p:(source)

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

    在您的主 html 文件的 head 中。然后只需使用requireNode 而不是require

    【讨论】:

      【解决方案2】:

      例外情况是:

      AssertionError: missing path
           at Module.require (module.js:351:3)
           at require (internal/module.js:12:17)
           at Object.<anonymous> (D:\learning\index.js:1:77)
           at Module._compile (module.js:409:26)
           at Object.Module._extensions..js (module.js:416:10)
           at Module.load (module.js:343:32)
           at Function.Module._load (module.js:300:12)
           at Function._load (C:\Users\12885\AppData\Roaming\npm\node_modules\pm2\node_modules\pmx\lib\transaction.js:62:21)
      learning-0 (err):     at C:\Users\12885\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainer.js:217:23
      learning-0 (err):     at C:\Users\12885\AppData\Roaming\npm\node_modules\pm2\node_modules\async\lib\async.js:52:16
      

      解决办法是:

      var express = require(express); ---> var express = require('express');
      

      【讨论】:

        猜你喜欢
        • 2015-12-31
        • 1970-01-01
        • 2016-09-01
        • 2013-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-25
        • 2021-07-12
        相关资源
        最近更新 更多