Error [ERR_REQUIRE_ESM]: require() of ES Module during Cypress upgrade to the v10.0.1
See original GitHub issueCurrent behavior
When I try to upgrade Cypress to v10.0.1 I get “SyntaxError: Cannot use import statement outside a module”
Your configFile is invalid: /Users/xxx/Documents/Cypress/my_project/cypress.config.js
It threw an error when required, check the stack trace below:`
`/Users/xxx/Documents/Cypress/my_project/cypress.config.js:1
import { defineConfig } from "cypress";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1033:15)
at Module._compile (node:internal/modules/cjs/loader:1069:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at loadFile (/Users/xxxi/Library/Caches/Cypress/10.0.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js:103:14)
at EventEmitter. (/Users/xxx/Library/Caches/Cypress/10.0.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js:146:38)
at EventEmitter.emit (node:events:527:28)
at EventEmitter.emit (node:domain:475:12)
at process. (/Users/xxx/Library/Caches/Cypress/10.0.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:33:22)
at process.emit (node:events:527:28)
at process.emit (node:domain:475:12)
at emit (node:internal/child_process:938:14)
I’ve read that the solution for this issue is adding "type": "module"
in package.json but now I am getting another issue:
101 |
102 | try {
> 103 | return require(file)
| ^
104 | } catch (err) {
105 | originalError = err
106 | if (!err.stack.includes('[ERR_REQUIRE_ESM]') && !err.stack.includes('SyntaxError: Cannot use import statement outside a module')) {
107 | throw err
[Stack trace](http://localhost:55743/__launchpad/index.html#) Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/xxx/Documents/Cypress/my_project/cypress.config.js from /Users/xxx/Library/Caches/Cypress/10.0.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js not supported. Instead change the require of cypress.config.js in /Users/xxx/Library/Caches/Cypress/10.0.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js to a dynamic import() which is available in all CommonJS modules. at loadFile (/Users/xxx/Library/Caches/Cypress/10.0.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js:103:14) at EventEmitter. (/Users/xxxLibrary/Caches/Cypress/10.0.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_require_async_child.js:146:38) at EventEmitter.emit (node:events:527:28) at EventEmitter.emit (node:domain:475:12) at process. (/Users/xxxLibrary/Caches/Cypress/10.0.1/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:33:22) at process.emit (node:events:527:28) at process.emit (node:domain:475:12)
Do you have any ideas on how to solve it?
Cypress Version
10.0.1
Package Manager
npm
Operating system
Mac
Other
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top GitHub Comments
Are you able to share your existing project? Ideally a repo we could clone, but if that’s too much trouble, a
package.json
,cypress.json
andcypress/plugins/index.js
would be a good start.If you could re-run the migration with
DEBUG=cypress*
and include the logs from the terminal, that would help, too!It looks like it’s incorrectly generating a ES modules based config; if you just want to make it work, you could change to using CJS:
If you could share a slimmed down version of the repo you want to migrate, that’d be great - we can work through it and find out what’s going wrong, so others can have a smooth migration process.
Released in
10.0.2
.This comment thread has been locked. If you are still experiencing this issue after upgrading to Cypress v10.0.2, please open a new issue.