gulp typescript throws error TS2300: Duplicate identifier 'moment'
Asked Answered
A

3

8

I have an Angular application generated using Yeoman gulp typescript generator.

Suddenly without any apparent reason (change in project) during build typescript started throwing errors:

.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 content of below files for the reference. I removed 'tsd:install' from gulp script task to prevent build from overriding d.ts files and tsd.d.ts file. Then tried to modify tsd.d.ts to fix problem (I tried to remove moment-node, moment, change order,I also tried to edit 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 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" />
Amoy answered 5/10, 2015 at 20:40 Comment(0)
P
6

If you point to a specific version like 1.4.1 instead of "master" for the ref: - I think it will fix it for you. It work for me.

{
   "version": "v4",
  "repo": "borisyankov/DefinitelyTyped",
  "ref": "1.4.1",
  "path": ".tmp/typings",
  "bundle": ".tmp/typings/tsd.d.ts"
}
Printmaker answered 5/10, 2015 at 23:15 Comment(1)
Adding the explicit version 1.4.1 in tsd.json, worked. Good timing :-)Cragsman
B
1

The error message is misleading. I believe this real reason for the orignal error is due to the type definition file for moment using a TypeScript feature which your current version does not support. Run the following to get the latest version of gulp-typescript and then I think everything will work for you, without having to restrict your TSD file to a specific revision. Restricting it to a specific revision will have its own issues.

npm install [email protected] --save-dev
Butlery answered 6/10, 2015 at 18:2 Comment(0)
N
0

delete kendo all.d.ts then rebuild your website in wwwroot. this works for me

Nev answered 11/4, 2017 at 2:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.