Version
v22.3.0
Platform
Darwin MacBook-Pro.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:13:18 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6030 arm64
Subsystem
No response
What steps will reproduce the bug?
- Run these commands
npm init
npm install plawright
touch main.js
touch module.js
- Add
"type":"module" in package.json
- Paste this code into
module.js
import { test } from "playwright/test";
export const dummy = ''
- Paste this code into
main.js
import {mock} from "node:test";
// The module to mock could be anything
mock.module('node:fs')
const {dummy} = await import("./module.js");
- Run
node --experimental-test-module-mocks --experimental-require-module --experimental-detect-module module.js. Normally everything worked correctly
Note: the flags are needed to be able to use mock.module
- Run
node --experimental-test-module-mocks --experimental-require-module --experimental-detect-module main.js. Here you should see an error:
import { test } from "playwright/test";
^^^^
SyntaxError: The requested module 'playwright/test' does not provide an export named 'test'
What if I use const { test } = await import("playwright/test") instead
Now module.js is:
const { test } = await import("playwright/test");
export const dummy = ''
I get a new error:
node:internal/util:399
validateFunction(original, 'original');
^
TypeError [ERR_INVALID_ARG_TYPE]: The "original" argument must be of type function. Received undefined
at promisify (node:internal/util:399:3)
at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:51:24844
at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:1:222
at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:52:19158
at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:1:222
at Object.<anonymous> (/path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:52:30370)
at Module._compile (node:internal/modules/cjs/loader:1460:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1544:10)
at Module.load (node:internal/modules/cjs/loader:1275:32)
at Module._load (node:internal/modules/cjs/loader:1091:12) {
code: 'ERR_INVALID_ARG_TYPE'
}
Node.js v22.3.0
How often does it reproduce? Is there a required condition?
It is reproduced every single time, normally without a condition.
What is the expected behavior? Why is that the expected behavior?
The expected behaviour is that the import occurs correctly and playwright is imported
What do you see instead?
An error (with import { test } from "playwright/test"):
import { test } from "playwright/test";
^^^^
SyntaxError: The requested module 'playwright/test' does not provide an export named 'test'
With const { test } = await import("playwright/test")
node:internal/util:399
validateFunction(original, 'original');
^
TypeError [ERR_INVALID_ARG_TYPE]: The "original" argument must be of type function. Received undefined
at promisify (node:internal/util:399:3)
at /path_to_project/mock-issue/node_modules/playwright/lib/utilsBundleImpl.js:51:24844
at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:1:222
at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:52:19158
at /path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:1:222
at Object.<anonymous> (/path_to_project/node_modules/playwright/lib/utilsBundleImpl.js:52:30370)
at Module._compile (node:internal/modules/cjs/loader:1460:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1544:10)
at Module.load (node:internal/modules/cjs/loader:1275:32)
at Module._load (node:internal/modules/cjs/loader:1091:12) {
code: 'ERR_INVALID_ARG_TYPE'
}
Node.js v22.3.0
Additional information
No response
Version
v22.3.0
Platform
Subsystem
No response
What steps will reproduce the bug?
"type":"module"in package.jsonmodule.jsmain.jsnode --experimental-test-module-mocks --experimental-require-module --experimental-detect-module module.js. Normally everything worked correctlynode --experimental-test-module-mocks --experimental-require-module --experimental-detect-module main.js. Here you should see an error:What if I use
const { test } = await import("playwright/test")insteadNow
module.jsis:I get a new error:
How often does it reproduce? Is there a required condition?
It is reproduced every single time, normally without a condition.
What is the expected behavior? Why is that the expected behavior?
The expected behaviour is that the import occurs correctly and playwright is imported
What do you see instead?
An error (with
import { test } from "playwright/test"):With
const { test } = await import("playwright/test")Additional information
No response