-
-
Notifications
You must be signed in to change notification settings - Fork 938
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
tsc can't resolve types for got 13 #2267
Comments
Got has been an ESM package since v12. You must have |
Got is a default export: import got from 'got'; |
saidly, I can't do that... I'd like to use |
Heads up that node16 module resolution does not work in Next.js projects. |
You only need for example, Another sulution is to upgrade typescript to 5.0 and set This works if you are using any tools to transpile or bundle your server project source files (including nodejs esm loader for examaple, if you are using This is beacuse nodejs esm loader can be more powerful then nodejs cjs hook. If you are using bundler or esm-loader ( But sadly, ts-node-esm does nothing but transpile, so you will need |
I hope that the fix goes in, we are not able to use |
So in the context of nextjs I'm not entirely sure there is a good path to support I created two branches with examples in the following repo one without ESM reproducing the similar issue we see here and one with ESM/node16. The second branch is where I attempted to follow what @sindresorhus was saying and update the With the ESM port I get errors when importing from the
related next issue vercel/next.js#46078 |
For context, my attempt at adding node16 support to next.js I don't think it is possible to make it work using the current setup. |
this change also breaks webstorm autocomplete |
My builds also started failing on v13 with |
Same problem |
* update code links for browser->waitUntil (#10446) * update code links for browser->waitUntil * update example link with SHA commit instead of main * New Crowdin updates (#10444) * New translations Donate.md (Bulgarian) * New translations Element.md (Polish) * New translations Donate.md (Bulgarian) * New translations Element.md (Polish) * New translations Donate.md (Bulgarian) * New translations Materials.md (Bulgarian) * New translations code.json (Bulgarian) * Recommend the runme extension for vs coders (#10449) * tabs vs spaces * Bump @typescript-eslint/parser from 5.59.6 to 5.59.7 (#10456) Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.59.6 to 5.59.7. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.59.7/packages/parser) --- updated-dependencies: - dependency-name: "@typescript-eslint/parser" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump @typescript-eslint/utils from 5.59.6 to 5.59.7 (#10457) Bumps [@typescript-eslint/utils](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/utils) from 5.59.6 to 5.59.7. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/utils/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.59.7/packages/utils) --- updated-dependencies: - dependency-name: "@typescript-eslint/utils" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump devtools-protocol from 0.0.1146845 to 0.0.1149535 (#10458) Bumps [devtools-protocol](https://github.com/ChromeDevTools/devtools-protocol) from 0.0.1146845 to 0.0.1149535. - [Changelog](https://github.com/ChromeDevTools/devtools-protocol/blob/master/changelog.md) - [Commits](ChromeDevTools/devtools-protocol@v0.0.1146845...v0.0.1149535) --- updated-dependencies: - dependency-name: devtools-protocol dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump aws-sdk from 2.1381.0 to 2.1386.0 (#10461) Bumps [aws-sdk](https://github.com/aws/aws-sdk-js) from 2.1381.0 to 2.1386.0. - [Release notes](https://github.com/aws/aws-sdk-js/releases) - [Commits](aws/aws-sdk-js@v2.1381.0...v2.1386.0) --- updated-dependencies: - dependency-name: aws-sdk dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump @types/jasmine from 4.3.1 to 4.3.2 (#10460) Bumps [@types/jasmine](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jasmine) from 4.3.1 to 4.3.2. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jasmine) --- updated-dependencies: - dependency-name: "@types/jasmine" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump @sveltejs/vite-plugin-svelte from 2.3.0 to 2.4.1 (#10465) Bumps [@sveltejs/vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte/tree/HEAD/packages/vite-plugin-svelte) from 2.3.0 to 2.4.1. - [Release notes](https://github.com/sveltejs/vite-plugin-svelte/releases) - [Changelog](https://github.com/sveltejs/vite-plugin-svelte/blob/main/packages/vite-plugin-svelte/CHANGELOG.md) - [Commits](https://github.com/sveltejs/vite-plugin-svelte/commits/@sveltejs/vite-plugin-svelte@2.4.1/packages/vite-plugin-svelte) --- updated-dependencies: - dependency-name: "@sveltejs/vite-plugin-svelte" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump @vitest/coverage-c8 from 0.30.1 to 0.31.1 (#10464) Bumps [@vitest/coverage-c8](https://github.com/vitest-dev/vitest/tree/HEAD/packages/coverage-c8) from 0.30.1 to 0.31.1. - [Release notes](https://github.com/vitest-dev/vitest/releases) - [Commits](https://github.com/vitest-dev/vitest/commits/v0.31.1/packages/coverage-c8) --- updated-dependencies: - dependency-name: "@vitest/coverage-c8" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump strip-ansi from 6.0.1 to 7.1.0 (#10463) Bumps [strip-ansi](https://github.com/chalk/strip-ansi) from 6.0.1 to 7.1.0. - [Release notes](https://github.com/chalk/strip-ansi/releases) - [Commits](chalk/strip-ansi@v6.0.1...v7.1.0) --- updated-dependencies: - dependency-name: strip-ansi dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump dependabot/fetch-metadata from 1.4.0 to 1.5.1 (#10455) Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 1.4.0 to 1.5.1. - [Release notes](https://github.com/dependabot/fetch-metadata/releases) - [Commits](dependabot/fetch-metadata@v1.4.0...v1.5.1) --- updated-dependencies: - dependency-name: dependabot/fetch-metadata dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * added new service to services list is named 'wdio-robonut-service' (#10454) * added new service have been named 'wdio-robonut-service' * fixed title mistake * added wdio-robonut-service to cli constants external section * New Crowdin updates (#10451) * New translations options.json (Bulgarian) * New translations current.json (Bulgarian) * New translations current.json (Bulgarian) * New translations current.json (Bulgarian) * New translations code.json (Bulgarian) * New translations current.json (Bulgarian) * New translations current.json (Bulgarian) * New translations footer.json (Bulgarian) * New translations navbar.json (Bulgarian) * New translations code.json (Bulgarian) * New translations current.json (Bulgarian) * New translations Browser.md (Bulgarian) * New translations Team.md (Bulgarian) * New translations code.json (Bulgarian) * New translations code.json (Bulgarian) * New translations Environment.md (Polish) * New translations Environment.md (Polish) * New translations Environment.md (Polish) * New translations Browser.md (Polish) * New translations Globals.md (Polish) * New translations Mock.md (Polish) * New translations Mock.md (Polish) * exporting the addTag method so it can be used (#10477) Co-authored-by: Luke Fitzgerald <luke.fitzgerald@nutrien.com> * New Crowdin updates (#10478) * New translations Modules.md (Polish) * New translations Modules.md (Polish) * Bump got from 12.6.1 to 13.0.0 (#10462) Bumps [got](https://github.com/sindresorhus/got) from 12.6.1 to 13.0.0. - [Release notes](https://github.com/sindresorhus/got/releases) - [Commits](sindresorhus/got@v12.6.1...v13.0.0) --- updated-dependencies: - dependency-name: got dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Revert got from v13 to v12.6.0 due to type issues ref sindresorhus/got#2267 * adjust test coverage * v8.10.6 * Remove addEnvironment * Setting the environment variables in the config * Adjust allure tests because of environment changes * Add environment changes of allure to documentation * Add addEnvironment function again as a deprecated function * Update packages/wdio-allure-reporter/src/common/api.ts Change the deprecation message Co-authored-by: Christian Bromann <git@bromann.dev> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Sri Harsha <12621691+harsha509@users.noreply.github.com> Co-authored-by: Christian Bromann <git@bromann.dev> Co-authored-by: Adam Christian <adam.christian@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Siarhei Kliushnikau <77188735+udarrr@users.noreply.github.com> Co-authored-by: lukefitz1 <lukefitz1@gmail.com> Co-authored-by: Luke Fitzgerald <luke.fitzgerald@nutrien.com> Co-authored-by: WebdriverIO Release Bot <bot@webdriver.io>
It also breaks tsoa route generation which makes use of the typescript library
EDIT: It works if I replace |
same problem as well |
v12 works with |
ESM is still dead in the water for 99% of real-world projects. Which is an improvement from 100% of like a year back. {
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"baseUrl": ".",
"module": "CommonJS",
"moduleResolution": "node",
"isolatedModules": true,
"esModuleInterop": true,
"strict": true,
"downlevelIteration": true,
"paths": {
"~/*": [
"./src/*"
],
"got": ["./node_modules/got/dist/source"]
}
}
} |
Did the required changes to get got package working. But now the packages slugify and sizeOf don't work. "module": "node16", // Changed this line from "ESNext" to "node16" To use got package |
@datner's solution will work for nextjs as long as you are not converting next to use ESM. You will still get the warning:
|
as far as I know, nextjs do not support and are not planning or intending to support esm, so I am not surprised that in general, it's really quite confusing that everyone supports the |
or you can patch got |
@trim21 share the patch then |
read the issue description again |
Here is the https://github.com/Hacksore/got-13-type-woes/tree/use-patch-package |
oops! |
I'm still confused as to why The documentation is rather scarce on the subject but tends to suggest |
why we need support this esm :( most framework dont support esm |
For those who wants to disable the warning, please refer to vercel/next.js#49432 and jaredwray/keyv#45:
You can override the webpack configuration with: /** @type {import('next').NextConfig} */
const nextConfig = {
// ...
webpack: (config) => {
// Ignore ALL webpack warnings produced by ./node_modules/keyv/src/index.js file
config.ignoreWarnings = [
{ module: /node_modules\/keyv\/src\/index\.js/ },
];
return config;
},
};
module.exports = nextConfig;
|
why intentionally break |
Typescript 5.2 now explicity fails to build when you mix See microsoft/TypeScript#54567
(or some variation of that). This means anyone upgrading to 5.2 and using got 13.0.0 will suddenly hit this error. Using the above from @datner, I managed to get a repo working but ran into another error. The other error - I used this change to "paths": {
"got": ["./node_modules/got/dist/source/index.js"]
}, I figured I'd mention it here now that 5.2 is out and this may become a larger issue before the end of the year. |
@timeimp yeah if you use |
I also can't get |
@dandv add this to your jest config: /**
* "Not a ts-jest issue" but a jest one. Consider vitest?
* this morphs "./some/relative/path.js" to "./some/relative/path"
* https://github.com/kulshekhar/ts-jest/issues/1057
*/
moduleNameMapper: {
"^(\\.\\.?\\/.+)\\.js$": "$1",
}, Not sure thats exactly it, but I suspect this might help. Maybe. |
@datner: that didn't work, unfortunately. Same error. |
To avoid problems I use the package wrapper |
But got-cjs is not updated. It is still 12. In my case |
same problem |
Unfortunately certain customers that are using my SDK (that relies on Got) are also experiencing the same issue and it becomes a bit of a problem as it's not feasible for them to try all the solutions listed in this thread. I decided to give the Fetch API a go instead and it seems to do the trick |
Another workaround in case it's useful:
|
If you want to make it work and you are on the latest TS 5.2.2, you can also set |
I couldn't get any of the above solutions working with my setup so I created my own type file with some of the got API functions I use. It is by no means complete but it removes the warnings and it is strongly typed.
|
I extended @micthiesen 's solution to be a bit more direct. You shouldn't need to add it to File:
|
Here's a workaround for Next.js@13: declare module 'got' {
import * as got from 'got/dist/source';
export = got;
} I don't get the author's intention. Hundreds of people have spent time searching for and fixing a problem that may not have existed. |
sadly I get this, this is not worth the trouble I'll just use one of the other alternatives, which is the beauty of the js ecosystem! |
people want to push ESM hard but not everyone can afford the switch. libraries should provide commonjs modules as an alternative but the maintainers just don't care 🥲 |
All the problems mentioned here are caused by Next.js, Jest, TypeScript, and incorrect tsconfig, not Got. I understand it's easier to blame all the problems in the world on Got rather than your favorite tooling, but it's also not productive. I have provided a straight forward guide on how to use TypeScript with ESM that works. If you don't want to move to ESM, that's fine. You can continue to use an older version that is already stable. The ecosystem cannot stand still just because some users refuse to move on. TypeScript had years to prepare for ESM, but they did not. Same with Jest. ESM was developed in the open and anyone could participate, including the TypeScript team. It had been in development for 10 years. Node.js released initial ESM support in Node.js 12.17 in May 2020, 2 years later (!), TypeScript finally added support for ESM. ESM has been available for almost 3 years now. |
Describe the bug
got 13 types exports breaks tsconfig.json
"moduleResolution": "Node"
and package.json"type": "module"
Actual behavior
Expected behavior
should resolve types
...
Code to reproduce
re-produce repo:
https://github.com/trim21/got-type
Checklist
fix:
The text was updated successfully, but these errors were encountered: