playwright: [BUG] svelte + 1.18.0-alpha: SyntaxError: The requested module '@playwright/test' does not provide an export named 'PlaywrightTestConfig'

Context:

  • Playwright Version: @playwright/test@1.18.0-alpha-jan-10-2022
  • Operating System: Linux
  • Node.js version: v16.13.2
  • Browser: <didn’t reach this part>
  • Extra:

System:

  • OS: Linux 5.15 NixOS 22.05 (Quokka) 22.05 (Quokka)
  • Memory: 740.97 MB / 15.51 GB
  • Container: Yes

Binaries:

  • Node: 16.13.2 - /nix/store/1s5l90kdzz5ii4bafi2dnyzv3smziq49-nodejs-16.13.2/bin/node
  • npm: 8.1.2 - /nix/store/1s5l90kdzz5ii4bafi2dnyzv3smziq49-nodejs-16.13.2/bin/npm

Languages:

  • Bash: 5.1.12 - /run/current-system/sw/bin/bash

Code Snippet

# Skeleton project, Typescript, Eslint, Prettier
npm init svelte@next svelte-playwright
cd svelte-playwright
npm install

# Typescript, "tests", true, false
npm init playwright
npx playwright test

I get: Error: playwright.config.ts: Cannot import a typescript file from an esmodule.

try 1.18.0-alpha:

npm i --save-dev @playwright/test@1.18.0-alpha-jan-10-2022
PW_EXPERIMENTAL_TS_ESM=1 npx playwright test

I get:

(node:62468) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Using config at /home/bbigras/dev/svelte-playwright/playwright.config.ts
file:///home/bbigras/dev/svelte-playwright/playwright.config.ts:1
import { PlaywrightTestConfig, devices } from '@playwright/test';
         ^^^^^^^^^^^^^^^^^^^^
SyntaxError: The requested module '@playwright/test' does not provide an export named 'PlaywrightTestConfig'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at ModuleJob.run (node:internal/modules/esm/module_job:181:5)
    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/svelte-playwright/node_modules/@playwright/test/lib/loader.js:260:28)
    at Loader.loadConfigFile (/home/bbigras/dev/svelte-playwright/node_modules/@playwright/test/lib/loader.js:77:18)
    at loadConfig (/home/bbigras/dev/svelte-playwright/node_modules/@playwright/test/lib/runner.js:91:24)
    at loadConfigFromDirectory (/home/bbigras/dev/svelte-playwright/node_modules/@playwright/test/lib/runner.js:98:24)
    at Runner.loadConfigFromFile (/home/bbigras/dev/svelte-playwright/node_modules/@playwright/test/lib/runner.js:107:22)
    at runTests (/home/bbigras/dev/svelte-playwright/node_modules/@playwright/test/lib/cli.js:148:18)
    at Command.<anonymous> (/home/bbigras/dev/svelte-playwright/node_modules/@playwright/test/lib/cli.js:73:7)

Describe the bug

maybe related to #7121

Same thing with v1.18.1

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Typescript and ESM are not yet best friends, replace first line with:

import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';

I am now receiving this error after upgrading from 1.17.2 to 1.19.2

If I alter file node_modules/@playwright/test/lib/loader.js

  isModule = false;    // <---  force this to false
  if (isModule) {
    return await esmImport(); 
  }

then it starts working again.

Also using the generated playwright.config.ts file does not resolve this issue.

Typescript and ESM are not yet best friends, replace first line with:

import type { PlaywrightTestConfig } from '@playwright/test';

Hi, I’ve just updated playwright to “@playwright/test”: “^1.18.1” and I got the same configuration error since then: Error: playwright.config.ts: Cannot import a typescript file from an esmodule.

and your suggestion is not working for me 😦

I have already a configuration file and I don’t think I need to type npx playwright init after the update, right?

We’ll probably want to make npm init playwright to generate esm-friendly code, so leaving open.

So, I added a very basic playwright.config.ts and everything works perfectly now:

/** @type {import('@playwright/test').PlaywrightTestConfig} */

const config = { testDir: './tests/e2e' }
export default config

Update to the 1.21 (alpha version).

pnpm up @playwright/test@next pnpm exec playwright install

I got that as well. #11755 (comment)

Hi, check if in your package.json file you have the field type:'module'. I got that maybe for previous “trial and error” tests and deleting it I solved the problem. Hope that’ll solve yours as well 😃

I have type:'module' in package.json for other necessary purposes. Besides it was working fine with version 1.17.2. How come version 1.18.0 and 1.18.1 require to remove type:'module'? That doesn’t make sense to me.