Importieren von lodash in angular2 + typescript application

Ich habe eine harte Zeit versucht, um die lodash Module importiert. Ich habe meine setup-Projekt mit npm+schlucken, und halten Sie schlagen die gleiche Wand. Ich habe versucht, die regelmäßige lodash, aber auch lodash-es.

Den lodash npm-Paket: (hat eine index.js Datei in das root-Paket-Ordner)

import * as _ from 'lodash';    

Ergebnisse in:

error TS2307: Cannot find module 'lodash'.

Den lodash-es-npm-Paket: (hat einen defaut-export in lodash.js ich das Paket-Stammverzeichnis)

import * as _ from 'lodash-es/lodash';

Ergebnisse in:

error TS2307: Cannot find module 'lodash-es'.   

Sowohl die gulp-task und webstorm Bericht das gleiche Problem.

Lustige Tatsache, dies gibt keine Fehler:

import 'lodash-es/lodash';

... aber natürlich gibt es kein "_" ...

Meine tsconfig.json-Datei:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules"
  ]
}

Meine gulpfile.js:

var gulp = require('gulp'),
    ts = require('gulp-typescript'),
    uglify = require('gulp-uglify'),
    sourcemaps = require('gulp-sourcemaps'),
    tsPath = 'app/**/*.ts';

gulp.task('ts', function () {
    var tscConfig = require('./tsconfig.json');

    gulp.src([tsPath])
        .pipe(sourcemaps.init())
        .pipe(ts(tscConfig.compilerOptions))
        .pipe(sourcemaps.write('./../js'));
});

gulp.task('watch', function() {
    gulp.watch([tsPath], ['ts']);
});

gulp.task('default', ['ts', 'watch']);

Wenn ich das richtig verstehe, moduleResolution:'Knoten' in meiner tsconfig zeigen sollte, die import-statements zu den node_modules-Ordner, wo lodash und lodash-es sind installiert. Ich habe auch versucht viele verschiedene Möglichkeiten zum importieren: absolute Pfade, relative Pfade, aber nichts scheint zu funktionieren. Irgendwelche Ideen?

Falls nötig, kann ich ein kleines zip-Datei um das problem zu veranschaulichen.

InformationsquelleAutor der Frage Davy | 2016-01-07

Schreibe einen Kommentar