Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate identifier with @types/node 10.0 #25342

Closed
1 of 4 tasks
rbirkgit opened this issue Apr 26, 2018 · 42 comments
Closed
1 of 4 tasks

Duplicate identifier with @types/node 10.0 #25342

rbirkgit opened this issue Apr 26, 2018 · 42 comments

Comments

@rbirkgit
Copy link

If you know how to fix the issue, make a pull request instead.

  • I tried using the @types/xxxx package and had problems.
  • I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • Mention the authors (see Definitions by: in index.d.ts) so they can respond.
    • Authors: @.types/node 10.0

With v9.6.6 everything was fine with my Angular project. Upgraded to 10.0.0 and now I get the following errors running my unit tests:

Error: 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.dom.d.ts(12210,11): error TS2300: Duplicate identifier 'URL'. node_modules/typescript/lib/lib.dom.d.ts(12226,13): error TS2300: Duplicate identifier 'URL'. node_modules/typescript/lib/lib.dom.d.ts(14282,11): error TS2300: Duplicate identifier 'URLSearchParams'. node_modules/typescript/lib/lib.dom.d.ts(14309,13): error TS2300: Duplicate identifier 'URLSearchParams'.

@westy92
Copy link
Contributor

westy92 commented Apr 26, 2018

I was just about to log this same issue!

I tried this:

npm init
npm i -g typescript
npm i --save-dev @types/node
tsc --init
touch index.ts
tsc

I get these same errors.

@westy92
Copy link
Contributor

westy92 commented Apr 26, 2018

Adding additional mention for the latest author: @rbuckton.

@allada
Copy link
Contributor

allada commented Apr 26, 2018

I am also seeing this. The last push broke our build with this same error.

@elarbee
Copy link

elarbee commented Apr 26, 2018

Also getting this. Looks like a conflict with Typescript in my case.
Fixed it by downgrading to v9.6.7

@westy92
Copy link
Contributor

westy92 commented Apr 26, 2018

Yes. In the OP's post, the conflict is with lib.dom.d.ts. I also see conflits with lib.d.ts and lib.es2017.full.d.ts.

@pshihn
Copy link

pshihn commented Apr 26, 2018

yep. seeing this as well.

@epheph
Copy link

epheph commented Apr 26, 2018

Experienced this issue as well, fixed by downgrading @types/node to v9.6.7

@westy92
Copy link
Contributor

westy92 commented Apr 26, 2018

We're still using the latest LTS (8), so we solved this (for now) by using ^8.0.0.

@rbuckton
Copy link
Collaborator

I will be able to look at this tonight.

@styfle
Copy link
Contributor

styfle commented Apr 27, 2018

You can get an idea of the impact of this breaking change with @dependabot Dependabot compatibility score
Probably most TS users are including @types/node which is causing the duplicate identifier and failing CI.

@rbuckton Thanks for looking into this 👍

@jantimon
Copy link
Contributor

Quick fix:

npm i @types/node@8.0.0

@abramenal
Copy link

abramenal commented Apr 27, 2018

For old-fashioned guys with nodejs v6.x.x - npm i --save-dev @types/node@6

@robertbradleyux
Copy link

robertbradleyux commented Apr 27, 2018

This was broken because these classes were changed to be globally exported, line 2380 in the current file. See the history comparison below:

bffb032#diff-7d84e08967cded0b99ed4328aab0a1a8

I was just about to pull and make the changes but looks like @rbuckton is already ahead of me in the process.

@styfle
Copy link
Contributor

styfle commented Apr 27, 2018

@robertbradleyux In node 10.0.0, The URL class is also available on the global object so this seems correct.

@rbuckton Is there a way to tell TypeScript to only define the class if it is not already defined?

In this case, both node and the browser implement the same WHATWG URL Standard so this is similar to setTimeout which has a different return type in Node.js than the browser https://nodejs.org/dist/latest-v10.x/docs/api/timers.html

Somehow TypeScript is able to handle the setTimeout so surely it could handle the global URL, right?


Update I see there is already a pull request to revert this change #25356

@ghost
Copy link

ghost commented Apr 27, 2018

After clearing my npm cache I am still getting the original error

@rbuckton
Copy link
Collaborator

@kgorlick This won't show up until the types publisher publishes the updated types to npm.

@rbuckton
Copy link
Collaborator

@styfle, NodeJS and DOM have slight differences in their implementations of the WHATWG URL standard (e.g. the NodeJS version has a toJSON() that isn't in the DOM version, and the DOM version has a static createObjectURL method that does not appear in the NodeJS version).

@Mulperi
Copy link

Mulperi commented Feb 17, 2019

Getting this error
with "@types/node": "^11.9.4",

node_modules/@types/node/index.d.ts:75:15 - error TS2300: Duplicate identifier 'SharedArrayBuffer'.

75 declare class SharedArrayBuffer {
~~~~~~~~~~~~~~~~~

node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts:24:11
24 interface SharedArrayBuffer {
~~~~~~~~~~~~~~~~~
'SharedArrayBuffer' was also declared here.
node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts:46:13
46 declare var SharedArrayBuffer: SharedArrayBufferConstructor;
~~~~~~~~~~~~~~~~~
and here.

node_modules/@types/node/index.d.ts:83:15 - error TS2451: Cannot redeclare block-scoped variable 'custom'.

etc.....

@Flarna
Copy link
Contributor

Flarna commented Feb 17, 2019

@Mulperi I think your issue is different to the above and related to the change of interface SharedArrayBuffer to class SharedArrayBuffer done in #32878.

@SimonSchick I think this should be changed back as it is actually just a forward declaration.

@SimonSchick
Copy link
Contributor

@Flarna this will only work if you load dom typings tho, node typings should work without loading dom typings..

@Flarna
Copy link
Contributor

Flarna commented Feb 17, 2019

It's not dom it's es2017.sharedmemory which is included in 3.1 typings via /// <reference lib="es2018" /> but older typescript versions do not support the reference lib directive.
Forward declaration is used to avoid that need the everyone has to include it manually. Forward declarations shall be an interface as interfaces merge with classes whereas classes are not allowed to be defined twice. So using class for a forward declaration breaks builds where the lib with the real definition is included.

@SimonSchick
Copy link
Contributor

@Flarna would simply adding /// <reference lib="es2017.sharedmemory" /> to /index.d.ts work in this case?

@SimonSchick
Copy link
Contributor

Also relevant since Atomics is still missing from those typings 🤔

@Flarna
Copy link
Contributor

Flarna commented Feb 17, 2019

Nope as /// <reference lib has been introduced in typescript 3.0 and the effected file is that one which is used for 2.1...3.0.
@Mulperi Which typescript version do you use? I expect it's <3.1.

@jmeberlein
Copy link

I'm also getting this problem. And changing to a previous version of @types/node is not a feasible option, since @types/connect uses *, pulls @^11.9, and causes conflicts in the test suite.

@SimonSchick
Copy link
Contributor

@Flarna I'm currently travelling, could you perhaps look into this?

@Flarna
Copy link
Contributor

Flarna commented Feb 18, 2019

@jmeberlein Which typescript version do you use? I expect it's <3.1.

@Flarna
Copy link
Contributor

Flarna commented Feb 18, 2019

created #33177. Hard to tell when this get's merged as CI is in a bad state currently.

@jmeberlein
Copy link

Typescript version ^2.9.2 in package.json, resolving to 2.9.2 in npm-shrinkwrap.json

@samuelt1
Copy link

samuelt1 commented Jan 3, 2020

why is this story closed? It seems to be broken still.

@wooliesx-apirillo
Copy link

why is this story closed? It seems to be broken still.

This was resolved almost a year ago, so it seems it was fixed but has now regressed. I'd probably open a new issue.

@thameurr
Copy link

thameurr commented Apr 2, 2020

ng] ERROR in node_modules/@types/node/index.d.ts:73:11 - error TS2300: Duplicate identifier 'IteratorResult'. [ng] 73 interface IteratorResult<T> { } [ng] ~~~~~~~~~~~~~~ [ng] node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6 [ng] 41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>; [ng] ~~~~~~~~~~~~~~ [ng] 'IteratorResult' was also declared here. [ng] node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6 - error TS2300: Duplicate identifier 'IteratorResult'. [ng] 41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>; [ng] ~~~~~~~~~~~~~~ [ng] node_modules/@types/node/index.d.ts:73:11 [ng] 73 interface IteratorResult<T> { } [ng] ~~~~~~~~~~~~~~ [ng] 'IteratorResult' was also declared here.

Problem still not resolved

@Flarna
Copy link
Contributor

Flarna commented Apr 2, 2020

@thameurr Please note that you comment on an issue closed quite a while ago. I assume you use a different set of @types/node, typescript,... versions then that ones mentined in this issue.

Could you create a new issue with instructions how to reproduced where up to date versions of the packages are used?

@grantis
Copy link

grantis commented Apr 20, 2020

I got this problem with @types/node: "13.9.5" and it was fixed by rolling back to "12.12.31" 🤷‍♂️

Type error: Duplicate identifier 'ProcessEnv'

@MarkLeMerise
Copy link

This issue was still occurring for me with TypeScript 4.0.2. Installing @types/node at version 14.6.0 seemed to make the errors go away when running tsc --noEmit.

@koshuang
Copy link

Got the same error. It's fixed when I add "skipLibCheck": true into tsconfig.json.

@andrevmatos
Copy link
Contributor

andrevmatos commented Nov 8, 2021

@types/node@16.11.6 is affected by this; I got the issue with typescript@4.4.4 and yarn:

yarn run v1.22.17
$ .../project/node_modules/.bin/tsc
../node_modules/@types/node/buffer.d.ts:97:14 - error TS2661: Cannot export 'Buffer'. Only local declarations can be exported from a module.

97     export { Buffer };
                ~~~~~~

Found 1 error.
error Command failed with exit code 2

Related: #56043

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests