Gulp typescript throws error TS2300: duplicate identifier 'moment'

I have an Angular application created using the Yeoman gulp typescript generator.

Suddenly, for no apparent reason (change in the project), typescript errors started throwing during typescript builds:

.tmp/typings/moment/moment-node.d.ts(6,16): error TS2300: Duplicate identifier 'moment'. [22:08:34] [TypeScript] TypeScript error: .tmp/typings/moment/moment-node.d.ts(6,16): error TS2300: Duplicate identifier 'moment'. .tmp/typings/moment/moment.d.ts(8,13): error TS2300: Duplicate identifier 'moment'. 

See below below files for reference. I removed the "tsd: install" task from the gulp script to prevent the collection from the overridden d.ts files and the tsd.d.ts file. Then I tried to change tsd.d.ts to fix the problem (I tried to remove moment-node, moment, order of change, I also tried to change moment.d.ts and moment- node.d.ts, nothing worked: /).

My tsd.json file:

 { "version": "v4", "repo": "borisyankov/DefinitelyTyped", "ref": "master", "path": ".tmp/typings", "bundle": ".tmp/typings/tsd.d.ts" } 

My script.js (gulp taks):

 'use strict'; var path = require('path'); var gulp = require('gulp'); var conf = require('./conf'); var browserSync = require('browser-sync'); var $ = require('gulp-load-plugins')(); var tsProject = $.typescript.createProject({ target: 'es5', sortOutput: true }); gulp.task('scripts', ['tsd:install'], function () { return gulp.src(path.join(conf.paths.src, '/app/**/*.ts')) .pipe($.sourcemaps.init()) .pipe($.tslint()) .pipe($.tslint.report('prose', { emitError: false })) .pipe($.typescript(tsProject)).on('error', conf.errorHandler('TypeScript')) .pipe($.concat('index.module.js')) .pipe($.sourcemaps.write()) .pipe(gulp.dest(path.join(conf.paths.tmp, '/serve/app'))) .pipe(browserSync.reload({ stream: true })) .pipe($.size()) }); 

Generated by tsd.d.ts:

 /// <reference path="angular-local-storage/angular-local-storage.d.ts" /> /// <reference path="angular-ui-router/angular-ui-router.d.ts" /> /// <reference path="angularjs/angular-animate.d.ts" /> /// <reference path="angularjs/angular-cookies.d.ts" /> /// <reference path="angularjs/angular-mocks.d.ts" /> /// <reference path="angularjs/angular-resource.d.ts" /> /// <reference path="angularjs/angular-sanitize.d.ts" /> /// <reference path="angularjs/angular.d.ts" /> /// <reference path="bootstrap/bootstrap.d.ts" /> /// <reference path="d3/d3.d.ts" /> /// <reference path="jquery/jquery.d.ts" /> /// <reference path="moment/moment.d.ts" /> /// <reference path="moment/moment-node.d.ts" /> /// <reference path="toastr/toastr.d.ts" /> 
+8
typescript momentjs gulp yeoman tsd
source share
3 answers

If you specify a specific version, for example 1.4.1, instead of "master" for the link: - I think it will fix it for you. This works for me.

 { "version": "v4", "repo": "borisyankov/DefinitelyTyped", "ref": "1.4.1", "path": ".tmp/typings", "bundle": ".tmp/typings/tsd.d.ts" } 
+6
source share

The error message is misleading. I believe the real cause of the orignal error is related to the type definition file for when you used the TypeScript function, which your current version does not support. Run the following command to get the latest version of gulp - typescript, and I think that everything will work for you, without having to limit your TSD file to a specific revision. Limiting it to a specific audit will have its own problems.

 npm install gulp-typescript@2.9.2 --save-dev 
+1
source share

delete kendo all.d.ts, then rebuild your site in wwwroot. it works for me

0
source share

All Articles