当我尝试使用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上。
发布于 2014-09-23 21:47:24
通常,当某个脚本试图引用另一个尚未加载的脚本时,就会出现这些引用错误。基本上,您注册脚本的顺序很重要。被引用的脚本应该在使用它的脚本之前注册。
本文提供了对这个问题的一个很好的解释(尽管使用的是JQuery的$选择器,而不是lodash _):http://jquery-howto.blogspot.nl/2013/02/referenceerror-jquery-is-not-defined.html。
因此,我将检查您的.js文件的注册顺序及其依赖关系。
发布于 2014-12-11 23:24:29
这是Lo-dash的一个问题。当前的edge版本似乎有一个修复,请参阅this thread
一种快速的解决方案似乎是用<script>require('lodash')</script>取代<script src="path_to_lodash.js"></script>
https://stackoverflow.com/questions/25989098
复制相似问题