Es funktioniert, aber jetzt habe ich mein Projekt geändert [email protected]
mit seinen neuen rollup
und es2015
Bündelung/Module. Ich bin nicht in der Lage, lodash
richtig zu bekommen.Typoskript importieren Sie `lodash` - mit` es2015` Modulen?
lodash
ist da, aber an der falschen Stelle - die Methoden, die ich brauchen, sind in _.default
npm Schritte
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
Was geschieht?
Update
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", ...]
Update 2
Vielleicht ist es etwas mit Chrome Debugger + Rollup? Ich änderte meinen Code import _ from "lodash";
und es funktioniert gut - außer in der Debugger-Konsole ...
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(…)
und in der Tat, wenn ich an den main.js
schauen und nicht die Quelle Karte, ich sehe Anzeichen von Bäumen schütteln (?):
console.log(">>> _.keys(_): " + lodash.keys(lodash).slice(10, 20));
var sorted = lodash.sortBy(photos, function (o) {
return o[sort.key];
});
es scheint, wie mein Problem mit der Chrome-Debug-Konsole ist, aber ich bin nicht sicher, wie es zu lösen ...
'VM1912: 1 Uncaught Reference: VERSION nicht definiert ist (...)' – michael