私は、1.5、typescript 2.4.0、moment:2.18.1、およびgulpを使用してプロジェクトを作成しています。TypeScript + moment.js:エラーTS2307: 'moment'モジュールを見つけることができません
は、ここに私のtsconfig.json
です:
{
"files": [
"src/app/main.ts",
"types/**/*.ts"
],
"compilerOptions": {
"noImplicitAny": false,
"target": "es2015",
"allowSyntheticDefaultImports": true
}
}
私date-range-picker.component.ts
を内部。私はmain documentationで提案されたように、モーメントのlibをインポートしています:tsifyプラグインに依存しているタスクを組み立てるメイン一気プロジェクトのために正常に動作します
import * as moment from 'moment';
:
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));
});
しかしのコンパイルについて私は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`));
});
:
date-range-picker/date-range-picker.component.ts(2,25): error TS2307: Cannot find module 'moment'.
これを修正するにはどうすればよいですか?
var tsProject = ts.createProject( 'tsconfig.json'、{})を試すことができます。 、おそらくこれは助けます –
結果は同じです – Elias