Closed sandersn closed 3 years ago
I'm seeing the same thing when I tried to move to 3.6.1-rc
ERROR in C:/Users/Eric/code/vscode-gitlens/node_modules/@types/node/index.d.ts
ERROR in C:/Users/Eric/code/vscode-gitlens/node_modules/@types/node/index.d.ts(177,11):
TS2300: Duplicate identifier 'IteratorResult'.
ERROR in C:/Users/Eric/code/vscode-gitlens/node_modules/typescript/lib/lib.es2015.iterable.d.ts
ERROR in C:/Users/Eric/code/vscode-gitlens/node_modules/typescript/lib/lib.es2015.iterable.d.ts(41,6):
TS2300: Duplicate identifier 'IteratorResult'.
@eamodio You need to update the version of @types/node
you are using as this has already been addressed in that types package.
@rbuckton Excellent -- that worked! Thank you!
I upgraded to typescript 3.7.2 today and now am seeing the same error:
node_modules\@types\node\index.d.ts(72,11): error TS2300: Duplicate identifier 'IteratorResult'
I have upgraded @types\node to latest (12.12.6), but still getting the error. Any suggestions?
@JontyMC where is the other location that it is defined? I just ran into that issue as well:
node_modules/@types/node/index.d.ts:169:11 - error TS2300: Duplicate identifier 'IteratorResult'.
169 interface IteratorResult<T> { }
~~~~~~~~~~~~~~
node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6
41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
~~~~~~~~~~~~~~
'IteratorResult' was also declared here.
However, for me it was because I didn't have @types/node installed in that project. For you I see that you already have this installed. Could it be a reference in your tsconfig lib prop that's causing this? What do you have listed in there?
Yeah, that was the issue, thanks. I had:
"./node_modules/@types/**/*.d.ts"
If this helps anyone else, I'm using Aurelia, and had to remove the above from aurelia.json in transpiler > dtsSource.
Here's a good post that explains how type definitions work https://blog.angular-university.io/typescript-2-type-system-how-do-type-definitions-work-in-npm-when-to-use-types-and-why-what-are-compiler-opt-in-types/
@eamodio You need to update the version of
@types/node
you are using as this has already been addressed in that types package.
@rbuckton Exactly where is this addressed already? IteratorResult is still there at: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/index.d.ts#L72
@rbuckton we need a flag to disable this error. The release notes say we need to fix this on case-by-case basis, but we cannot fix it for libraries that we cannot control, so due to this one feature we cannot adopt Typescript 3.7.
Why can't we opt in to this behaviour as has been the case with other stricter checking changes?
@nealeu this is handled by the "typesVersions"
entry in package.json: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/50adc95acf873e714256074311353232fcc1b5ed/types/node/package.json#L4-L10
When the TypeScript compiler searches for types (either using the "types"
entry in your compiler options or automatic type directive detection when an "types"
is not present), it will search in node_modules/@types/node
and encounter this package.json. This informs the compiler to redirect the request for node_modules/@types/node/index.d.ts
to node_modules/@types/node/ts3.2/index.d.ts
, which does not contain IteratorResult
.
However, if your build is configured such that you are explicitly adding node_modules/@types/node/index.d.ts
(either via "files"
or "includes"
in your tsconfig.json), the compiler does not perform this redirection.
@rbuckton Thanks. Sorry to have required spoon-feeding.
@rbuckton I'm running into this issue even when upgrading to the latest @types/node^10 on TypeScript 3.7.2. any advice would be appreciated!
Here are the errors:
node_modules/@types/node/index.d.ts:72:11 - error TS2300: Duplicate identifier 'IteratorResult'.
72 interface IteratorResult<T> { }
~~~~~~~~~~~~~~
node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6
41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
~~~~~~~~~~~~~~
'IteratorResult' was also declared here.
node_modules/@types/node/index.d.ts:93:15 - error TS2451: Cannot redeclare block-scoped variable 'custom'.
93 const custom: symbol;
~~~~~~
node_modules/@types/node/ts3.2/util.d.ts:6:15
6 const custom: unique symbol;
~~~~~~
'custom' was also declared here.
node_modules/@types/node/ts3.2/util.d.ts:9:15
9 const custom: unique symbol;
~~~~~~
and here.
node_modules/@types/node/index.d.ts:96:15 - error TS2451: Cannot redeclare block-scoped variable 'custom'.
96 const custom: symbol;
~~~~~~
node_modules/@types/node/ts3.2/util.d.ts:6:15
6 const custom: unique symbol;
~~~~~~
'custom' was also declared here.
node_modules/@types/node/ts3.2/util.d.ts:9:15
9 const custom: unique symbol;
~~~~~~
and here.
node_modules/@types/node/ts3.2/util.d.ts:6:15 - error TS2451: Cannot redeclare block-scoped variable 'custom'.
6 const custom: unique symbol;
~~~~~~
node_modules/@types/node/index.d.ts:93:15
93 const custom: symbol;
~~~~~~
'custom' was also declared here.
node_modules/@types/node/index.d.ts:96:15
96 const custom: symbol;
~~~~~~
and here.
node_modules/@types/node/ts3.2/util.d.ts:9:15 - error TS2451: Cannot redeclare block-scoped variable 'custom'.
9 const custom: unique symbol;
~~~~~~
node_modules/@types/node/index.d.ts:93:15
93 const custom: symbol;
~~~~~~
'custom' was also declared here.
node_modules/@types/node/index.d.ts:96:15
96 const custom: symbol;
~~~~~~
and here.
node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6 - error TS2300: Duplicate identifier 'IteratorResult'.
41 type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
~~~~~~~~~~~~~~
node_modules/@types/node/index.d.ts:72:11
72 interface IteratorResult<T> { }
~~~~~~~~~~~~~~
'IteratorResult' was also declared here.
Found 6 errors.
// package.json
{
"dependencies": {
"apollo-cache-inmemory": "^1.6.2",
"apollo-client": "^2.6.4",
"apollo-link": "^1.2.11",
"apollo-link-context": "^1.0.17",
"apollo-link-error": "^1.1.12",
"apollo-link-http": "^1.5.16",
"d3": "^5.7.0",
"date-fns": "^1.30.1",
"ecstatic": "^3.3.0",
"graphiql": "^0.13.0",
"graphql-tag": "^2.10.1",
"history": "^4.9.0",
"raven-js": "^3.27.0",
"react": "^16.8.6",
"react-apollo": "^2.5.6",
"react-dom": "^16.8.6",
"styled-components": "^4.3.2",
"tzjs": "^1.0.4"
},
"devDependencies": {
"@types/d3": "^5.0.1",
"@types/graphql": "^0.13.4",
"@types/history": "^4.7.2",
"@types/node": "^12.12.7",
"@types/react": "^16.8.19",
"@types/react-dom": "^16.8.4",
"@types/styled-components": "^4.1.16",
"apollo-codegen": "^0.20.2",
"chokidar-cli": "^1.2.1",
"parcel-bundler": "^1.12.3",
"prettier": "^1.18.0",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"tslint-react": "^4.1.0",
"typescript": "^3.7.2"
},
"engines": {
"npm": "^6.0.0"
}
}
// tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"esModuleInterop": true,
"jsx": "react",
"lib": ["es2017", "es2017.object", "dom", "dom.iterable", "esnext.asynciterable"],
"noEmitHelpers": true,
"importHelpers": true,
"strict": true,
"noEmitOnError": true,
"outDir": "bin",
"incremental": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": false,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"types": []
},
"parcelTsPluginOptions": {
"transpileOnly": false
}
}
@rbuckton I am having the same issue that @ethanrubio described
@ethanrubio How are you doing your build? Are you using tsc
directly, or another build tool like gulp
, etc.? From what you've posted, node_modules/@types/node/index.d.ts
is still somehow being directly added to your compilation.
@rbuckton I'm invoking tsc directly or using an npm build script such as:
"scripts": {
"build": "npm run ts-build && npm run lint && npm run parcel-build",
"lint": "tslint -p . -t verbose",
"parcel-build": "NODE_ENV=production parcel build --no-cache --out-dir ../java/appserver/src/main/resources/appserver/web/bin-js ./ts/bundle.ts ./ts/bundle-graphiql.ts ./ts/bundle-components.ts",
"ts-build": "tsc --noEmit -p ."
},
Even running the script like the defined npm build script ts-build
or running a tsc
command manually, results in the previous error that I posted.
Do you see errors when you run npm run ts-build
, or do they only show up when you run npm run parcel-build
?
@rbuckton it stills errors with npm run ts-build
only
Sorry, I just noticed you mentioned running ts-build
also results in the errors. I noticed you have "types": []
in your tsconfig.json. This tells the compiler to not generate automatic type references. How are your node types being referenced then? Are you using /// <reference types="node" />
in one of your source files?
@rbuckton I see. we just have them added to our dev dependencies. is that not suitable? we aren't using /// <reference types="node" />
.
In general, unless something has a /// <reference types="node" />
somewhere, if you have "types": []
then we shouldn't be including the NodeJS types at all. We exclude "node_modules/**/*"
by default, so it shouldn't be automatically included. One possibility might be in how your project is structured. Is your tsconfig.json
in the same directory as your node_modules
? If not, or if you have additional node_modules
directories underneath your project, then it is possible it could be included from there.
You could try restricting your included files by adding an "include": [...]
to your tsconfig to ensure you are only including your sources by default (i.e. "include": ["src/**/*"]
):
{
"compilerOptions": { ... },
"parcelTsPluginOptions": { ... },
"include": ["paths/to/your/sources"]
}
If the build then fails because it can't resolve a NodeJS built-in module like "fs", then you are moving in the right direction. You could then modify your "types"
entry in tsconfig.json to "types": ["node"]
to ensure the NodeJS type definitions are included automatically, which should use the correct module resolution behavior.
I also get the following error with TS3.7.2 and @types/node@10.12.18
node_modules/@types/node/index.d.ts(200,11): error TS2300: Duplicate identifier 'IteratorResult'.
node_modules/typescript/lib/lib.es2015.iterable.d.ts(41,6): error TS2300: Duplicate identifier 'IteratorResult'.
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"outDir": "build/",
"rootDir": ".",
"target": "es2015",
"moduleResolution": "node",
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": false,
"inlineSourceMap": true,
"inlineSources": true,
"noImplicitThis": false,
"noImplicitAny": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"lib": [
"esnext"
]
},
}
So far tried to play around with types
typeRoots
include
and exclude
without luck. Any ideas?
@m19: Are you using tsc
to perform your build or a different build process/orchestrator like Gulp/Jake?
@rbuckton it seems somehow I was stuck at @types/node
10.10.x
and I just managed to fix it by updating to 10.17.5
. Sorry!
Hi, I'm getting the same errors as well:
node_modules/@types/node/index.d.ts(66,11): error TS2300: Duplicate identifier 'IteratorResult'.
node_modules/typescript/lib/lib.es2015.iterable.d.ts(41,6): error TS2300: Duplicate identifier 'IteratorResult'.
Using Node: v9.11.2
, "@types/node": "9.6.55"
, "typescript": "3.7.3"
and "grunt-ts": "6.0.0-beta.17"
, "grunt": "0.4.5"
.
Global: tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"baseUrl": ".",
"declaration": true,
"lib": [
"esnext",
"dom"
],
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"target": "es2017"
},
"exclude": [
"node_modules"
]
}
Module: tsconfig-lib.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib"
},
"include": ["./src/**/*.ts"],
"types": ["node", "mocha"]
}
I've tried to play with all mentioned blocks (like types
and exclude
), but nothing helped.
Any help is appreciated.
Per @rbuckton, you'll need to update @types/node
.
Per @rbuckton, you'll need to update
@types/node
.
Unfortunately, it was the first thing I tried and that didn't help.
The latest versions of the node
declarations directly include the required lib
, rather than forward declaring anything - are you sure? The latest version of node
declarations quite literally do not include IteratorResult
.
@weswigham One of the submodules stored the old version of @types/node
. Updated it as well and error's gone. Thanks for your help!
Whow?! That really hearts! :)
I had an issue with obsoleted @types/nodes in the parent folder
Nevertheless, thanks @rbuckton and @weswigham to this issue thread was REALLY useful to track all possible scenarios of this really painful and recurring issue.
I would really love to see this extracted into a separate troubleshooting document :)
@eamodio You need to update the version of
@types/node
you are using as this has already been addressed in that types package.
This issue can be closed, the StackOverflow question also suggests that it resolves this issue.
As mentioned, please refer to https://stackoverflow.com/questions/57331779/typescript-duplicate-identifier-iteratorresult if you are still experiencing problems.
I used type/node version 17.0.3 I still get the same error. Can you specify which version can be better.
Version: npm : 6.13.4 angular: 8 node: v10.19.0 storybook angular: 6.0.12
I have used 17.0.3 version of type/node. The issue still persist. Can you specify which can be the best version to be used. Please help me out. Its urgent.
Version: npm : 6.13.4 angular: 8 node: v10.19.0 storybook angular: 6.0.12
https://github.com/microsoft/TypeScript/pull/32324 shows some errors in the user tests with duplicate identifier IteratorResult between the es2015 lib and
@types/node
. The docker tests also fail, probably for a similar reason.32303 should fix some of these errors; we should make sure that the docker tests compile without error since those are open source partner teams in microsoft. Not sure if the fix will be in our code or theirs.