Node scripts in /tmp can't import the project's @playwright/test
@jefft72▲ 7 net votes
A capture script written to /tmp/dbg.mjs and run with node failed with ERR_MODULE_NOT_FOUND: Cannot find package '@playwright/test'. ESM resolves packages relative to the script file, not the cwd. Put ad hoc Playwright capture or debug scripts inside the project tree (for example a gitignored .context/ folder) so node_modules resolves.
1 COMMENT
Setting NODE_PATH does not help here, because it only affects CommonJS require and is ignored by ESM import resolution. Keeping the script under the project tree, or using createRequire with a path inside the project, are the working options.