【发布时间】:2016-09-29 07:24:52
【问题描述】:
它曾经可以工作,但现在我将我的项目更改为 ionic2@RC.0,并使用其新的 rollup 和 es2015 捆绑/模块。我无法正确获取lodash。
lodash在那里,但是在错误的地方——我需要的方法在_.default
npm 步骤
npm install lodash --save
npm install @types/lodash --save-dev --save-exact
javascript
import * as _ from "lodash";
console.log( Object.keys(_) ) // ["default", "__moduleExports"]
console.log(_.default.VERSION) // 4.16.2
发生了什么事?
更新
import _ from "lodash"; // imports as lodash, not _
// Chrome debugger console:
console.log(_) // VM2037:1 Uncaught ReferenceError: _ is not defined(…)
console.log(lodash) // function
console.log(Object.keys(lodash)) // returns: VM2075:1 ["templateSettings", "after", "ary", "assign", ...]
更新 2
也许这与 Chrome 调试器 + 汇总有关?我将我的代码更改为import _ from "lodash";,它工作正常——除了在调试器控制台中......
console.log(">>> _.keys(_): " + _.keys(_).slice(10, 20));
// >>> _.keys(_): bindAll,bindKey,castArray,chain,chunk,compact,concat,cond,conforms,constant
// and the _.sortBy() below works fine
var sorted = _.sortBy(photos, function (o) {
return o[sort.key];
});
// BUT, in the Chrome debugger (at breakpoint)
console.log(_) // VM2037:1 Uncaught ReferenceError: _ is not defined(…)
事实上,当我查看main.js 而不是源映射时,我看到了摇树的迹象(?):
console.log(">>> _.keys(_): " + lodash.keys(lodash).slice(10, 20));
var sorted = lodash.sortBy(photos, function (o) {
return o[sort.key];
});
我的问题似乎出在 Chrome 调试控制台上,但我不知道如何解决它...
【问题讨论】:
-
VM1912:1 Uncaught ReferenceError: VERSION is not defined(…)
标签: typescript ecmascript-6 ionic2 lodash