-
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
Unable to compile TypeScript with "moduleResolution": "bundler" option in v5 #27731
Comments
+1 on this. I am having the same issue. |
@karlhorky thank you for opening this issue. Internally we still largely use TS4 so there are some scenarios that still popup as problematic. I don't have an ETA on a fix for this, but if folks want to contribute a fix (with tests) we would be happy to review. |
i just read through that closed issue. i am also running into the issue with ^13.1.0 |
I encountered this problem today while setting up a Next.JS project. To confirm the issue I created a greenfield project to test it. WorkaroundFor anyone looking for a workaround who lands here before they see the other related issues (now closed), here is a workaround copied from issue #27448: {
// Leave this section as is.
"compilerOptions": {
"module": "esnext",
"moduleResolution": "bundler",
"plugins": [],
"paths": {}
},
// Add this section.
"ts-node": {
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node"
}
},
} Recreating the issue in a new projectHere are my steps and results. I hope this is helpful for whoever ends up working on a resolution. System infoOS: macOS 14.0 Beta (23A5337a) Steps to reproduce1. Create a next app using
|
I thought I tested this with a brand new Next.js project. We also have a test for projects using What is going on -- is this test not configured correctly? |
Not sure if this is the issue (as I'm not sure exactly how the system-tests work), but I noticed that the package.json file specifies Would the TS version in that system-test be causing the test to be a false positive? (For what it's worth, like others here I'm still getting the same error with Cypress 13, so it would seem that the issue is not resolved) |
I am having the same issue. |
Any contributors with a functioning dev environment that can execute (I’d be happy to, but reading through My hypothesis is that the I could be completely wrong on this, hence why I don’t want to go to the trouble of getting the project running locally just to find out I’m wrong, if it would only take someone else a few minutes to verify. |
This needs to be resolved as a fresh default installation of Next.js npx create-next-app also causes the error
when running Cypress |
I am able to reproduce this issue error with the slimmed types configuration: {
"compilerOptions": {
"module": "es2015",
"moduleResolution": "bundler",
}
} I have only been able to produce this error when the Cypress configuration is using typescript, i.e. I do not see this error when the Cypress configuration is The I have been able to make a few tweaks to our setup and it seems resolves the |
Okay - while working through how any changes would impact the existing expectations, I have found a few possible option that may work for a few of you depending on your current setup...
or
TS_NODE_COMPILER_OPTIONS="{\"module\":\"CommonJS\",\"moduleResolution\":\"node\"}" or
"ts-node": {
"compilerOptions": {
"esm": true,
"module": "esnext",
"moduleResolution": "bundler",
},
}, module.exports = {
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
}; If anyone tries these options out and they work, that'd be helpful to know if any of these are reasonable paths forward given the various project setups someone can have with various typescript versions & needs. |
Spoke with @elevatebart earlier, it sounds we are loading our configuration via ts-node and bundled file should be going through the webpack-processor. He was suggesting we may considering either specifying typescript support OR move towards only generating .js/.cjs cypress configuration files — this is the pattern other frameworks are trending towards. |
So in Cypress 13.5.0 we still need to use workaround with ts-node? Cypress complains on usage of |
… conflicts with jest -> cypress-io/cypress#27731
Cypress type declaration workaround: cypress-io/cypress#27731 (comment)
Does this issue means it's not possible to use cypress with Next.js? Or is there a working workaround? "next": "13.5.6", |
This PR updates the testing guides to use App Router and TypeScript, also updates `/examples` to show `app` and `pages` examples. ## Overview - [x] Create a new "Testing" section that is shared between `app` and `pages`. - [x] Explain the differences between E2E, unit testing, component testing, etc. - [x] Recommend E2E for `async` components as currently none of the tools support it. - [x] Update setup guides for **Cypress**, **Playwright**, and **Jest** with latest config options, and examples for `app` and `pages`. - [x] Add new guide for **Vitest** - [x] Clean up `/examples`: use TS, show `app` and `pages` examples, match docs config ## Cypress - [x] E2E Tests - [x] Component Testing - [x] Client Components - [x] Server Components - [ ] `async` components **Blockers:** - TS: `Option 'bundler' can only be used when 'module' is set to 'es2015' or later`. In **tsconfig.json** compilerOptions, Next.js uses "moduleResolution": "bundler", changing it to "node" fixes the issue but it can have repercussions. - cypress-io/cypress#27731 - Version 14 is currently not supported for component testing - cypress-io/cypress#28185 ## Playwright - [x] E2E Tests ## Jest - [x] Unit Testing - [x] Client Components - [x] Server Components - [ ] `async` components: testing-library/react-testing-library#1209 - [x] 'server-only': #54891 - [x] Snapshot Testing **Blockers:** - TS: testing-library/jest-dom#546 - None of the solutions in the issue work with Next.js v14.0.4 and TS v5 ## Vitest - [x] Unit Testing - [x] Client Components - [x] Server Components - [ ] `async` components - [x] 'server-only' - [x] Update vitest example - [x] Handles CSS, and CSS modules imports - [x] Handles next/image ## Other - #47448 - #47299
I confirmed that this PR does not fix this. I didn't really expect it to anyway. #28528 |
Also facing the same issue on next.js 14. "moduleResolution": "node" fixes it but it can have side effects on Next.js code. |
This PR updates the testing guides to use App Router and TypeScript, also updates `/examples` to show `app` and `pages` examples. ## Overview - [x] Create a new "Testing" section that is shared between `app` and `pages`. - [x] Explain the differences between E2E, unit testing, component testing, etc. - [x] Recommend E2E for `async` components as currently none of the tools support it. - [x] Update setup guides for **Cypress**, **Playwright**, and **Jest** with latest config options, and examples for `app` and `pages`. - [x] Add new guide for **Vitest** - [x] Clean up `/examples`: use TS, show `app` and `pages` examples, match docs config ## Cypress - [x] E2E Tests - [x] Component Testing - [x] Client Components - [x] Server Components - [ ] `async` components **Blockers:** - TS: `Option 'bundler' can only be used when 'module' is set to 'es2015' or later`. In **tsconfig.json** compilerOptions, Next.js uses "moduleResolution": "bundler", changing it to "node" fixes the issue but it can have repercussions. - cypress-io/cypress#27731 - Version 14 is currently not supported for component testing - cypress-io/cypress#28185 ## Playwright - [x] E2E Tests ## Jest - [x] Unit Testing - [x] Client Components - [x] Server Components - [ ] `async` components: testing-library/react-testing-library#1209 - [x] 'server-only': vercel#54891 - [x] Snapshot Testing **Blockers:** - TS: testing-library/jest-dom#546 - None of the solutions in the issue work with Next.js v14.0.4 and TS v5 ## Vitest - [x] Unit Testing - [x] Client Components - [x] Server Components - [ ] `async` components - [x] 'server-only' - [x] Update vitest example - [x] Handles CSS, and CSS modules imports - [x] Handles next/image ## Other - vercel#47448 - vercel#47299
@ahmadbilaldev @arbuznik can either of you try |
@AtofStryker I upgraded to
{
"devDependencies": {
"cypress": "https://cdn.cypress.io/beta/npm/13.6.3/linux-x64/fix/set_module_resolution_with_commonjs-0481c7af5d4085004b91dd644d7a4c8d97ea1b00/cypress.tgz"
}
} I was able to remove my workaround lines below from
{
- // Old "moduleResolution": "Node" option required for Cypress
- // /~https://github.com/cypress-io/cypress/issues/26308#issuecomment-1663592648
- //
- // TODO: Remove this when Cypress supports "moduleResolution": "Bundler"
- // /~https://github.com/cypress-io/cypress/issues/27448
- // /~https://github.com/cypress-io/cypress/issues/27731
- "ts-node": {
- "compilerOptions": {
- "module": "es2015",
- "moduleResolution": "node"
- }
- },
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler"
}
} |
@AtofStryker FYI, I gave this a try and it resolved the issue for me. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior
Originally reported by @MasonM in #26308 and closed because of Cypress v13.0.0 - but this release does not fix this
cc @jennifer-shehane @lmiller1990 - ideally #26308 would be unlocked and reopened, if you can do that
Copied issue below:
If you have a TypeScript project using the new "moduleResolution": "bundler" setting introduced in TypeScript 5, any attempts to run tests will cause the following error:
Desired behavior
Tests run successfully
Test code to reproduce
Reproduction 1
Courtesy of @MattyBalaam: /~https://github.com/MattyBalaam/cypress-ts-import
Reproduction 2
See error message and
tsconfig.json
below:tsconfig.json
Cypress Version
13.1.0
Node version
v18.17.1
Operating System
macOS Ventura 13.5 (22G74)
Debug Logs
No response
Other
No response
The text was updated successfully, but these errors were encountered: