Typescript: "target": "es2015" and @types/node (v10.0.0) cause Duplicate identifier errors

Created on 28 Apr 2018  路  5Comments  路  Source: microsoft/TypeScript



TypeScript Version: 2.8.3 and 2.9.0-dev.20180427


Search Terms:

Within GitHub on this repo: "Node 10", "Node 10.0.0", "Duplicate identifier", "Duplicate Identifier 'URL'"

Code

Sample code (can probably even be an empty file)

console.log();

tsconfig.json:

{
  "compilerOptions": {
    "target": "es2015",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    "sourceMap": true,                     /* Generates corresponding '.map' file. */
    "outDir": "./dist",                        /* Redirect output structure to the directory. */
    "rootDir": "./src",                       /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */

    /* Strict Type-Checking Options */
    "strict": true,                           /* Enable all strict type-checking options. */
    "noImplicitAny": true,                 /* Raise error on expressions and declarations with an implied 'any' type. */
    "strictNullChecks": true,              /* Enable strict null checks. */
    "strictFunctionTypes": true,           /* Enable strict checking of function types. */
    "noImplicitThis": true,                /* Raise error on 'this' expressions with an implied 'any' type. */
    "alwaysStrict": true,                  /* Parse in strict mode and emit "use strict" for each source file. */

    /* Additional Checks */
    "noUnusedLocals": true,                /* Report errors on unused locals. */
    "noImplicitReturns": true,             /* Report error when not all code paths in function return a value. */

  }
}

Expected behavior:

This should compile without errors

Actual behavior:

I get the following output:

node_modules/@types/node/index.d.ts(2381,15): error TS2300: Duplicate identifier 'URL'.
node_modules/@types/node/index.d.ts(2399,15): error TS2300: Duplicate identifier 'URLSearchParams'.
node_modules/@types/node/index.d.ts(2417,14): error TS2661: Cannot export 'URL'. Only local declarations can be exported from a module.
node_modules/@types/node/index.d.ts(2417,19): error TS2661: Cannot export 'URLSearchParams'. Only local declarations can be exported from a module.
node_modules/typescript/lib/lib.es6.d.ts(19249,11): error TS2300: Duplicate identifier 'URL'.
node_modules/typescript/lib/lib.es6.d.ts(19265,13): error TS2300: Duplicate identifier 'URL'.
node_modules/typescript/lib/lib.es6.d.ts(19272,11): error TS2300: Duplicate identifier 'URLSearchParams'.
node_modules/typescript/lib/lib.es6.d.ts(19299,13): error TS2300: Duplicate identifier 'URLSearchParams'.
node_modules/typescript/lib/lib.es6.d.ts(21585,13): error TS2300: Duplicate identifier 'URL'.
node_modules/typescript/lib/lib.es6.d.ts(21586,13): error TS2300: Duplicate identifier 'URLSearchParams'.
node_modules/typescript/lib/lib.es6.d.ts(22348,11): error TS2300: Duplicate identifier 'URLSearchParams'.

Playground Link:

Related Issues:

Most helpful comment

I encounter this problem last day. The reason is @types/node:

After changing the version to 8.5.5锛宼he proble is fixed.

All 5 comments

I encounter this problem last day. The reason is @types/node:

After changing the version to 8.5.5锛宼he proble is fixed.

Wouldn't this be a matter of setting "lib": ["es2017"] to explicitly remove lib.dom.d.ts?

Looks like this should be fixed by https://github.com/DefinitelyTyped/DefinitelyTyped/pull/25356 but is unfortunately not published to npm.

Any idea when this will be published?

TIL about the lib option in tsconfig, that fixed it for now, thanks!

Given that we're just waiting for the DefinitelyTyped update to be published, I think this can be closed now.

Was this page helpful?
0 / 5 - 0 ratings