【问题标题】:Node-webkit: ReferenceError: _ is not definedNode-webkit:ReferenceError:_ 未定义
【发布时间】:2014-11-17 07:20:08
【问题描述】:

当我尝试使用 node-webkit 运行我的应用程序时出现错误:Node-webkit: ReferenceError: _ is not defined。我认为这是关于 Lo-dash,但在浏览器上一切正常。这是我的 index.html 代码:

<!DOCTYPE html>
<html ng-app="viewer">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="css/font-awesome.css">
    <script src="components.min.js"></script>
    <script src="app.min.js"></script>
</head>
<body>
<div id="content"></div>
<div ui-view></div>
</body>
</html>

在 components.min.js 中,我有我需要的所有组件 - lodash、angular 等。当我通过浏览器或 appJS 运行它时,我没有任何错误,仅在 node-webkit 上。

【问题讨论】:

    标签: javascript node.js webkit node-webkit


    【解决方案1】:

    当某些脚本试图引用另一个尚未加载的脚本时,通常会出现这些引用错误。基本上,您注册脚本的顺序很重要。引用的脚本应该在使用它的脚本之前注册。

    这个问题的一个很好的解释(尽管使用 JQuery 的 $ 选择器而不是 lodash _),在这篇文章中:http://jquery-howto.blogspot.nl/2013/02/referenceerror-jquery-is-not-defined.html

    因此,我将检查您的 .js 文件的注册顺序及其依赖项。

    【讨论】:

      【解决方案2】:

      这是 Lo-dash 的一个问题。当前的边缘版本似乎已经修复了它,请参阅this thread

      一个快速的解决方案似乎是将&lt;script src="path_to_lodash.js"&gt;&lt;/script&gt;替换为&lt;script&gt;require('lodash')&lt;/script&gt;

      【讨论】:

        猜你喜欢
        • 2020-03-16
        • 2013-05-02
        • 2017-05-09
        • 2019-02-19
        • 2018-03-28
        • 2014-10-26
        • 2016-09-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多