Cypress fails to run when type is `module`
See original GitHub issueCurrent behavior
When using typescript and setting type to module
in package.json cypress fails to run with
Desired behavior
Cypress runs
Test code to reproduce
The simplest config you could have like shown here https://github.com/cypress-io/cypress/issues/22795#issuecomment-1232507681 or the cypress.config.ts
can have
import { defineConfig } from "cypress";
export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
Cypress Version
10.9.0
Node version
v16.17.1 (fails also with v18)
Operating System
Ubuntu 22.04
Debug Logs
cypress:lifecycle:child:run_require_async_child:337341 configFile: /home/isgjevori/Documents/prog/cy/cypress.config.ts +0ms
cypress:lifecycle:child:run_require_async_child:337341 projectRoot: /home/isgjevori/Documents/prog/cy +0ms
cypress:lifecycle:child:run_require_async_child:337341 try loading /home/isgjevori/Documents/prog/cy/cypress.config.ts +23ms
cypress:lifecycle:child:run_require_async_child:337341 Loading file /home/isgjevori/Documents/prog/cy/cypress.config.ts +0ms
cypress:server:util:editors user has the following editors: [ { id: 'code', binary: 'code', name: 'Visual Studio Code' }, { id: 'vim', binary: 'vim', name: 'Vim' } ] +282ms
cypress:server:saved_state making saved state from /home/isgjevori/.cache/Cypress/10.9.0/Cypress/resources/app/packages/server +211ms
cypress:server:saved_state missing project path, looking for project here +0ms
cypress:lifecycle:child:run_require_async_child:337341 User is loading an ESM config file +2ms
cypress:lifecycle:child:run_require_async_child:337341 importing esm file file:///home/isgjevori/Documents/prog/cy/cypress.config.ts +0ms
cypress:server:saved_state state path for global mode +2ms
cypress:server:appdata path: /home/isgjevori/.config/Cypress/cy/production/projects/__global__/state.json +214ms
cypress:server:saved_state full state path /home/isgjevori/.config/Cypress/cy/production/projects/__global__/state.json +1ms
cypress:server:util:editors saved preferred editor: undefined +7ms
cypress:server:util:editors return available editors: [ { id: 'computer', name: 'File System', binary: 'computer' }, { id: 'code', name: 'Visual Studio Code', binary: 'code' }, { id: 'vim', name: 'Vim', binary: 'vim' } ] +0ms
cypress:server:saved_state making saved state from /home/isgjevori/.cache/Cypress/10.9.0/Cypress/resources/app/packages/server +5ms
cypress:server:saved_state missing project path, looking for project here +0ms
cypress:server:saved_state state path for global mode +7ms
cypress:server:appdata path: /home/isgjevori/.config/Cypress/cy/production/projects/__global__/state.json +12ms
cypress:server:saved_state full state path /home/isgjevori/.config/Cypress/cy/production/projects/__global__/state.json +0ms
cypress:launcher:linux firefox is running as a snap, changing profile path +0ms
cypress:launcher:linux Could not extract version from stdout using regex: { stdout: '', versionRegex: /^Mozilla Firefox ([^\sab]+)$/m } +0ms
cypress:lifecycle:child:run_require_async_child:337341 error loading file via native Node.js module loader exports is not defined in ES module scope +53ms
cypress:lifecycle:ProjectConfigIpc error loading config {
name: 'Error',
message: 'Your \x1B[33mconfigFile\x1B[39m is invalid: \x1B[94m/home/isgjevori/Documents/prog/cy/cypress.config.ts\x1B[39m\n' +
'\n' +
'It threw an error when required, check the stack trace below:',
stack: 'ReferenceError: exports is not defined in ES module scope\n' +
' at file:///home/isgjevori/Documents/prog/cy/cypress.config.ts:2:23\n' +
' at ModuleJob.run (node:internal/modules/esm/module_job:193:25)\n' +
' at async Promise.all (index 0)\n' +
' at async ESMLoader.import (node:internal/modules/esm/loader:533:24)\n' +
' at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)\n' +
' at async loadFile (/home/isgjevori/.cache/Cypress/10.9.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:106:14)\n' +
' at async EventEmitter.<anonymous> (/home/isgjevori/.cache/Cypress/10.9.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:116:32)',
type: 'CONFIG_FILE_REQUIRE_ERROR',
details: 'ReferenceError: exports is not defined in ES module scope\n' +
' at file:///home/isgjevori/Documents/prog/cy/cypress.config.ts:2:23\n' +
' at ModuleJob.run (node:internal/modules/esm/module_job:193:25)\n' +
' at async Promise.all (index 0)\n' +
' at async ESMLoader.import (node:internal/modules/esm/loader:533:24)\n' +
' at async importModuleDynamicallyWrapper (node:internal/vm/module:438:15)\n' +
' at async loadFile (/home/isgjevori/.cache/Cypress/10.9.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:106:14)\n' +
' at async EventEmitter.<anonymous> (/home/isgjevori/.cache/Cypress/10.9.0/Cypress/resources/app/node_modules/@packages/server/lib/plugins/child/run_require_async_child.js:116:32)',
isCypressErr: true,
messageMarkdown: 'Your `configFile` is invalid: `/home/isgjevori/Documents/prog/cy/cypress.config.ts`\n' +
'\n' +
'It threw an error when required, check the stack trace below:',
originalError: [Object]
} +334ms
### Other
_No response_
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Initializing Cypress v10 on a "type": "module" project ... - GitHub
Current behavior Initializing Cypress v10 on a new Next.js + TypeScript project results in an [ERR_UNKNOWN_FILE_EXTENSION] error.
Read more >Cypress Module Problem - Gleb Bahmutov
It seems if the application has type: module setting in its package.json , the Cypress plugins that runs in Node and tries to...
Read more >Troubleshooting | Cypress Documentation
First, find where the binary is installed using the cypress cache path command. If the smoke test fails to execute, check if a...
Read more >Cypress ParseError: 'import' and 'export' may appear only with ...
This error is caused by the presence of modern keywords like "import" and "export" when Cypress runs in the browser.
Read more >cypress-io/cypress - Gitter
Hello, when cypress tests run, it seems cypress_runner.js is downloaded from a <script> tag ... Property 'toMatchImageSnapshot' does not exist on type 'cy ......
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
@MateusNeres26 thanks, I was able to reproduce it with this project.
Any update on this? I tried
yarn patch cypress
to see if I could patch the offending code for my project, but I’m having trouble sorting out the source code with what gets installed in my project locally.