Eli*_*ias 5 javascript angularjs momentjs typescript gulp
我正在开发一个Web应用程序,使用angular 1.5,typescript 2.4.0,时刻:2.18.1,以及用于项目组装的gulp.
这是我的tsconfig.json:
{
"files": [
"src/app/main.ts",
"types/**/*.ts"
],
"compilerOptions": {
"noImplicitAny": false,
"target": "es2015",
"allowSyntheticDefaultImports": true
}
}
Run Code Online (Sandbox Code Playgroud)
我的内心date-range-picker.component.ts.我正在导入片段lib,正如主文档中提出的那样:
import * as moment from 'moment';
Run Code Online (Sandbox Code Playgroud)
哪个适用于依赖tsify插件的主要gulp项目组装任务:
var browserifyIt = browserify({
basedir: '.',
debug: true,
entries: paths.browserifyEntries,
cache: {},
packageCache: {}
}).plugin(tsify);
gulp.task('bundle', ['views'], function () {
return browserifyIt
.transform('babelify', {
presets: ['es2015'],
extensions: ['.ts']
})
.bundle()
.on('error', interceptErrors)
.pipe(source(fileNames.buildJs))
.pipe(ngAnnotate())
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write(paths.sourcemapPath))
.pipe(gulp.dest(paths.build));
});
Run Code Online (Sandbox Code Playgroud)
但是为了编译测试,我决定使用tsProject()的任务:
const testSrcPaths = {
....,
componentTests: 'src/app/components/**/*.test.ts',
....
};
gulp.task('component-tests:compile', function () {
return gulp.src(testSrcPaths.componentTests).pipe(tsProject())
.on('error', interceptErrors)
.js.pipe(gulp.dest(`${paths.testsDist}/components`));
});
Run Code Online (Sandbox Code Playgroud)
这导致以下错误:
date-range-picker/date-range-picker.component.ts(2,25):错误TS2307:找不到模块'时刻'.
可以做些什么来解决它?
最后,加入moduleResolution: "node"到compilerOptions解决我的问题.因此,最终采用以下tsconfig.json配置:
{
"files": [
"src/app/main.ts"
],
"compilerOptions": {
"noImplicitAny": false,
"target": "es2015",
"moduleResolution": "node"
}
}
Run Code Online (Sandbox Code Playgroud)
以下是可用于了解有关打字稿模块解析方法的更多信息的链接.
| 归档时间: |
|
| 查看次数: |
4029 次 |
| 最近记录: |