question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript 4.7 with new moduleResolution mode node16/nodenext does not resolve types

See original GitHub issue

Current 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:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
smmccabecommented, Jun 22, 2022

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.

0reactions
louisscruzcommented, Jul 8, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found