-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Next.js + TS not working out of the box #27448
Comments
Work around for now is change to "moduleResolution": "node" This makes basically no difference from what I can tell for Next.js, but broken out of the box is a bad look. I will try to patch this quickly. |
WorkaroundFor people looking for a temporary workaround, probably better to only apply the old, obsolete
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler"
},
+ // Old "moduleResolution": "Node" option required for Cypress
+ // https://github.com/cypress-io/cypress/issues/26308#issuecomment-1663592648
+ //
+ // TODO: Remove when issue is resolved https://github.com/cypress-io/cypress/issues/27448
+ "ts-node": {
+ "compilerOptions": {
+ "module": "ESNext",
+ "moduleResolution": "Node"
+ }
+ }
} |
We need to fix this in core asap, this is a showstopper, will look into it asap. |
Bit of background / rant, but I understand what we need to do now, I think. It's kind of unfortunate the JS ecosystem has headed in this direction... some context follows: I just read https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#moduleresolution-bundler in more detail to get an idea of what From the TS release notes: But in some ways, the original node resolution mode was already out of date. Most modern bundlers use a fusion of the ECMAScript module and CommonJS lookup rules in Node.js. For example, extensionless imports work just fine like in CommonJS, but when looking through the export conditions of a package, they’ll prefer an import condition just like in an ECMAScript file. To model how bundlers work, TypeScript now introduces a new strategy: --moduleResolution bundler. This is the real root of the endless complexity in the JavaScript ecosystem. Instead of trying to use the real module system that is supported by both browsers and Node.js natively, bundlers decided to just define our own in userland. It's a weird fusion of CommonJS and ES Modules.
Why can't I use I am suspecting this actual problem is this:
We hard-code
That's because, unlike the Next.js dev server, Cypress itself is an Electron app that does use
This seems to work, at least for the Next.js example. |
I have no idea if this is a breaking change or what the impact is, but trying: #27484 We will likely need some additional logic to handle resolving and running the |
Since you hit the
|
Yeah, I think we need a proper, big picture solution, endlessly patching every use case is really impractical and painful. I'll do a little more digging around this and see if we can actually simplify things - I think the complexity in Cypress is starting to leak out a bit.
mts will not work due to this override, I think this probably made sense a while ago, but not anymore, since using ESM is actually becoming a thing (well... kind of. It's not really ESM, but the weird "commonjs/ES module" mix, which is what module: bundler is all about).
I'm really disappointed TS actually supports this weird ESM/CJS mix of module systems - call it chimera.js if you will, since that's what it is - a hybrid between two module systems. TS is meant to be a superset of JS - I think that should include the module systems, which are CommonJS and ESM - supporting this weird bundler defined module system should have been outside the scope of TypeScript, imo. It's a little depressing that we have two perfectly servicable module systems, CommonJS and ESM (and Node.js supports both!!) yet hardly anyone is actually using either of them in their native form :'( |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Choose CT
I think we are not working with
"moduleResolution": "bundler"
https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#moduleresolution-bundler
Probably related: #26308
The text was updated successfully, but these errors were encountered: