got: Got 12.1.0 x Typescript 4.7.2 x Node 16.15 transpilation fails with moduleResolution=Node16
Describe the bug
- Node.js version: 16.15.0
- OS & version: Windows 11
Actual behavior
Requiring got and transpiling with Typescript 4.7 raises transpilation errors
node_modules/got/dist/source/core/options.d.ts(763,22): error TS2709: Cannot use namespace 'CacheableLookup' as a type.
node_modules/got/dist/source/core/options.d.ts(764,26): error TS2709: Cannot use namespace 'CacheableLookup' as a type.
node_modules/got/dist/source/core/options.d.ts(775,21): error TS2709: Cannot use namespace 'CacheableLookup' as a type.
node_modules/got/dist/source/core/options.d.ts(776,25): error TS2709: Cannot use namespace 'CacheableLookup' as a type.
node_modules/got/dist/source/core/options.d.ts(1125,29): error TS2709: Cannot use namespace 'CacheableLookup' as a type.
Code to reproduce
package.json
{
"name": "got-ts4.7-regression",
"version": "1.0.0",
"type": "module",
"dependencies": {
"got": "^12.1.0"
},
"devDependencies": {
"typescript": "^4.7.2"
}
}
tsconfig.json
{
"compilerOptions": {
"module": "Node16",
"moduleResolution": "Node16",
"target": "es6",
},
"exclude": [
"node_modules"
]
}
“moduleResolution”: “Node16” is apparently required for Typescript 4.7 support of the exports
field in package.json
Checklist
- I have read the documentation.
- I have tried my code with the latest version of Node.js and Got.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 12
- Comments: 22 (9 by maintainers)
Commits related to this issue
- Convert to ESM, enforce file single naming convention. Blocked by https://github.com/sindresorhus/got/issues/2051 — committed to dscalzi/Nebula by dscalzi 2 years ago
- TS: Migrate to nodenext moduleResolution, check libs Fixes error "'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`" with `got`. Details: <https://gith... — committed to polarsquad/cinode-api by mikkopiu a year ago
- fix type crash https://github.com/sindresorhus/got/issues/2051 — committed to transloadit/uppy by mifi a year ago
- Fix TypeScript issues See: sindresorhus/got#2051, cheeriojs/cheerio#2774 — committed to dogancelik/twdl by dogancelik a year ago
I would go with
2
. In the future, more packages are switching tonode16
, so if you choose1
, you’re just going to hit this problem with another package.Alternatively, you could maybe set
"skipLibCheck": true
in your tsconfig.I really feel like this issue should have a much higher priority. Almost all sindresorhus packages have been promoting ESM only for a long time, and now that TS finally have proper support, this issue alone prevents me from finally migrating a big TypeScript project to ESM.
Really hope someone picks this up soon, i will happily donate a cup of coffee to anyone moving on with this issue 😄 ❤️
I appreciate the push forward, but mainline releases really should be stable. The ESM requirement should have remained on a pre-release line until dependency issues were resolved. Yes, 11 is a fallback that most people use but new features all target 12.
Same, a little bit confused here. I cannot get this package to compile with TypeScript after the switch to ESM. Setting
skipLibCheck
totrue
incompilerOptions
is the only way to get this package to compile. Using TypeScript 4.7.3 and got 12.1.0.I feel like I’m missing something, does anyone have a barebones repo with TypeScript working?
I’ve released
then-busboy@5.2.1
andform-data-encoder@2.1.2
with these fixes. Thanks @Baune8D!I have opened PRs for both
form-data-encoder
andthen-busboy
https://github.com/octet-stream/form-data-encoder/pull/10 https://github.com/octet-stream/then-busboy/pull/34I temporarily solved this issue by removing
/// <reference types="node" resolution-mode="require"/>
fromnode_modules/cacheable-request/dist/types.d.ts
and runningnpx patch-package cacheable-request
, see Maxim-Mazurok/google-api-typings-generator@c1f1654
(#703)Now that https://github.com/sindresorhus/got/issues/2129 is closed, this is another issue that blocks
got
from being used in TypeScript with ESM becausecacheable-request
now requiresnode16
to be set due to:Frankly, last few releases from @sindresorhus (not only Got) been a sick joke introducing more problems to people that chose to follow his advises and use ESM.
We hear you @Baune8D ❤️ Unfortunately there’s just only me and @sindresorhus. I’m quite busy with full-time work, I’ll try to find time later this week to push this forward, but no promises. We encourage more people to make contributions ❤️
To fix this, we need to upgrade AVA to v4 and then upgrade
@sindresorhus/tsconfig
to v3. Contributions welcome.