[BUG] ReferenceError: module is not defined in ES module scope (with sveltekit)
See original GitHub issueContext:
System:
- OS: Linux 5.15 NixOS 22.05 (Quokka) 22.05 (Quokka)
- Memory: 1.61 GB / 15.51 GB
- Container: Yes
Binaries:
- Node: 16.13.2 - /nix/store/nwf4llpwqwmxbx38nwa1zvlhpnd956fg-nodejs-16.13.2/bin/node
- npm: 8.1.2 - /nix/store/nwf4llpwqwmxbx38nwa1zvlhpnd956fg-nodejs-16.13.2/bin/npm
Languages:
- Bash: 5.1.12 - /run/current-system/sw/bin/bash
Code Snippet
https://github.com/bbigras/sveltekit_playwright_githubactions
or
# skeleton project, no typescript, no eslint, no prettier
npm init svelte@next sveltekit_playwright_githubactions
cd sveltekit_playwright_githubactions
npm install
git init && git add -A && git commit -m "Initial commit"
# javascript
npm init playwright
git add -A && git commit -m "add playwright"
# replace "require" by "import" like in https://github.com/bbigras/sveltekit_playwright_githubactions/commit/b920a40c61de6b18b6e5bb61fa68047ad4865b2e
npx playwright test
Describe the bug
I can’t figure out how to use playwright with sveltekit (no typescript).
I get:
ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/bbigras/dev/sveltekit_playwright_githubactions/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///home/bbigras/dev/sveltekit_playwright_githubactions/playwright.config.js:107:1
at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
at async Promise.all (index 0)
at ESMLoader.import (node:internal/modules/esm/loader:281:24)
at importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
at Loader._requireOrImport (/home/bbigras/dev/sveltekit_playwright_githubactions/node_modules/@playwright/test/lib/loader.js:268:28)
at Loader.loadConfigFile (/home/bbigras/dev/sveltekit_playwright_githubactions/node_modules/@playwright/test/lib/loader.js:74:18)
at loadConfig (/home/bbigras/dev/sveltekit_playwright_githubactions/node_modules/@playwright/test/lib/runner.js:88:45)
at loadConfigFromDirectory (/home/bbigras/dev/sveltekit_playwright_githubactions/node_modules/@playwright/test/lib/runner.js:93:24)
at Runner.loadConfigFromFile (/home/bbigras/dev/sveltekit_playwright_githubactions/node_modules/@playwright/test/lib/runner.js:102:22)
at runTests (/home/bbigras/dev/sveltekit_playwright_githubactions/node_modules/@playwright/test/lib/cli.js:165:18)
at Command.<anonymous> (/home/bbigras/dev/sveltekit_playwright_githubactions/node_modules/@playwright/test/lib/cli.js:74:7)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Module is not defined in ES module scope in JavaScript
The error "Module is not defined in ES module scope" occurs when we try to use the `module.exports` CommonJS syntax in ES modules....
Read more >referenceerror: module is not defined in es module scope ...
The error "Module is not defined in ES module scope" occurs when we try to use the module.exports CommonJS syntax in ES modules....
Read more >ReferenceError: __dirname is not defined in ES module ...
I'm going through this tutorial on discord.js. When I ran the code as written, I got errors like SyntaxError: Cannot use import statement ......
Read more >Modules • Docs • SvelteKit
In case of an error, it redirects to the nearest error page. ts. function applyAction<. Success extends Record<string, unknown> | undefined = Record<string, ......
Read more >require is not defined : r/sveltejs
I'm using sveltekit with an endpoint that imports objection.js and knex.js for db queries. whenever I hit that endpoint, I get the error...
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 Free
Top 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
It seems I needed
export default config;
.Thank you very much @qbunt 😄
WSL is not a joy to use. I would love to use Windows normally.