Skip to content

[BUG] ReferenceError: module is not defined in ES module scope (with sveltekit) #12138

Closed

Description

Context:

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions