Typescript 4.7 with new moduleResolution mode node16/nodenext does not resolve types
See original GitHub issueCurrent behavior
Types are not correctly resolved when using typescript 4.7 with moduleResolution set to “node16”.
https://www.typescriptlang.org/docs/handbook/module-resolution.html
error TS2688: Cannot find type definition file for ‘cypress’.
Desired behavior
Types should be resolved.
Test code to reproduce
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022"],
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "node16",
"moduleResolution": "node16",
"allowJs": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"types": ["node", "cypress"]
}
}
Cypress Version
10.1.0
Other
I believe this being due to new module resolution logic requiring explicit extension. Currently the package.json
types
field just says types
(referring to the folder where historically it would’ve been inferred to use index.d.ts
) but now needs to be explicit and configured as types/index.d.ts
Issue Analytics
- State:
- Created a year ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >TypeScript and native ESM on Node.js - 2ality
In this blog post, I'll explain everything you need to know in order to use and produce native ECMAScript modules on Node.js.
Read more >Add file extension when '--moduleResolution' is 'node16' or ...
TypeScript 4.7 : ECMAScript Module Support: Add file extension when '--moduleResolution' is 'node16' or 'nodenext' ... TypeScript 4.7 checks package.json's type ...
Read more >Why doesn't the exports field of npm work in typescript?
Ensure moduleResolution in the consuming library is set to either Node16 or NodeNext in your tsconfig.json file.
Read more >tsc-esm-fix - npm
meta is not allowed. esbuild/1043: empty output for interface files that breaks reimport. moduleResolution: nodenext. Nightly build TypeScript ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I get the same problem, but the above fix doesn’t work. Also this isn’t a problem with cypress v9, just with cypress v10, at least for me. I’ve been using nodenext since typescript 4.5 as experimental and it has always worked fine with cypress up until now.
I think the blast radius of this issue might be larger than described here. I’m seeing the type issues mentioned above in TypeScript 4.5.2 in a Yarn PnP project. After “unplugging” and applying the fix from https://github.com/cypress-io/cypress/pull/22498, the issue goes away.