将lodash导入angular2 + typescript应用程序
我很难尝试导入lodash模块。我使用npm + gulp设置我的项目,并继续击中同一面墙。我尝试过常规的lodash,还有lodash-es。
lodash npm包:(包根文件夹中有一个index.js文件)
import * as _ from 'lodash';
结果是:
error TS2307: Cannot find module 'lodash'.
lodash-es npm包:(在lodash.js中有一个defaut导出我的包根文件夹)
import * as _ from 'lodash-es/lodash';
结果是:
error TS2307: Cannot find module 'lodash-es'.
gulp任务和webstorm都报告了同样的问题。
有趣的是,这不会返回错误:
import 'lodash-es/lodash';
......但当然没有“_”......
我的tsconfig.json文件:
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]}我的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']);如果我理解正确,我的tsconfig中的moduleResolution:'node'应该将import语句指向node_modules文件夹,其中安装了lodash和lodash-es。我也尝试了许多不同的导入方式:绝对路径,相对路径,但似乎没有任何工作。有任何想法吗?
如果有必要,我可以提供一个小的zip文件来说明问题。
函数式编程
绝地无双
随时随地看视频慕课网APP
相关分类