Definitions by: in index.d.ts) so they can respond.I use dom lib in my tsconfig.json and Awesome Typescript Loader:
{
"compilerOptions": {
"target": "ES2018",
"module": "ES6",
"moduleResolution": "node",
"lib": [
"es2018",
"dom",
"dom.iterable"
],
"alwaysStrict": true,
"strictNullChecks": true,
"disableSizeLimit": true,
"downlevelIteration": true,
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": true,
"typeRoots": [
"./node_modules/@types"
]
},
"awesomeTypescriptLoaderOptions": {
"useCache": true,
"transpileModule": true,
// for debugging purpose.
// "errorsAsWarnings": true
}
}
In the end of compile process ATL throws an error:
ERROR in [at-loader] ./node_modules/@types/node/index.d.ts:198:15
TS2451: Cannot redeclare block-scoped variable 'console'.
I open up this file and saw it in more detail:
node_modules/@types/node/index.d.ts
declare const console: Console;
Throws an error:
Cannot redeclare block-scoped variable 'console'.
lib.dom.d.ts(17118, 13): 'console' was also declared here.
node_modules/typescript/lib/lib.dom.d.ts
declare var console: Console;
Throws an error:
Cannot redeclare block-scoped variable 'console'.
index.d.ts(198, 15): 'console' was also declared here.
Questions:
1) Maybe i did something wrong?
2) If not 1, then what should i do?
facing this,
manually change this const to var will solve this temporarily & locally
please fix it
Thank you~
Since version 10.11.1 this is an issue, putting the version back to 10.11.0 fixes it for now. Hopefully a fix will come soon.
We also ran into the same problem here. Reverting to 10.11.0 works for now, but this should be rectified.
https://github.com/DefinitelyTyped/DefinitelyTyped/pull/29230
While loading node and dom typings at the same time is somewhat of an anti-pattern it seems that in certain cases node typings are loaded automatically if present hence it conflicts here but not in the tests.
congratulations! you release nodejs types that conflict with typescript! It's awesome!
I'm locking it in my package.json like this
"@types/node": "~10.10.3",
And issue is gone.
@SimonSchick wondering why loading both sets of typings is an anti-pattern and not finding anything about it on search engine. In our case, it's for an isomorphic package which needs to handle both cases : what would be a better way to do it ?
Wow, I didn't even know I have @types/node in my browser-only projects. And they are actually being used in compilation which is even more weird. Looking at the yarn.lock it seems like it's a direct dependency of rollup. I guess a proper solution for this issue would be removing it from rollup dependencies? 🤔
I noticed @SimonSchick has fixed one statement yesterday to address declare const console
But just for the sake of completeness, there are three additional places where const needs to be replaced with var to fix the error output for process, require and module as well.
node_modules/@types/node/index.d.ts(196,15): error TS2451: Cannot redeclare block-scoped variable 'process'.
node_modules/@types/node/index.d.ts(243,15): error TS2451: Cannot redeclare block-scoped variable 'require'.
node_modules/@types/node/index.d.ts(256,15): error TS2451: Cannot redeclare block-scoped variable 'module'.
It would be great to get those three lines fixed as well so tsc compiles again. Thanks!
greets
-act
@actraiser What are the conflicts there? I didn't notice any when I specifically added the dom typings to the node typings project.
The idea behind making these values const was that assigning process module and require is usually an error as it would break functionality (module and require are scoped for each module).
I am out for the rest of the day but I will approve any PR so revert these changes.
Hello @SimonSchick - I have opened the pull request at #29267 .
Using const does conflict with @types/webpack-env which declares process, require and module as well (using var):
@types/webpack-env/index.d.ts(203,13) require
@types/webpack-env/index.d.ts(254,13) module
@types/webpack-env/index.d.ts(262,13) process
Therfor, with the const declarations in @types/node in place, tsc will not compile.
greets
-act
Most helpful comment
Since version 10.11.1 this is an issue, putting the version back to 10.11.0 fixes it for now. Hopefully a fix will come soon.