playwright: [BUG]Error: Cannot find module '@playwright/test' Playwright Version 1.33.0
System info
- Playwright Version: Version 1.33.0
- Operating System: Windows 11
- Browser: [All, Chromium, Firefox, WebKit]
- Other info:
- Npm -v : 9.6.6
- Node -v: v18.16.0
- Editor: Visual studio code 1.78.2
Description: I have been having issues with playwright and javascript for days, I have been deleting node js, visual studio code with all the extentions, after reinstalling it’s the same error, I have the environment variables for node js also all set, and still, run constantly npm install, but still get the following error.
Test steps:
- Open visual studio code editor and open terminal on root of folder
- Run script: npm init playwright@latest
- After that I note that the node_modules is never installed
- It will give me an error Cannot find module ‘@playwright/test’ or its corresponding type declarations.ts(2307), so I always have to delete @//ts-check because it always gets installed even tho I select javascript, that comment gets also added on the playwright.config.js , /tests and /tests-examples, so I have to remove it
- After that I try to run on the root of the proyect: npx playwright test example.spec.js
- It will give me an error so I have to run: npm i -D @playwright/test
- After that I run npx playwright test example.spec.js and I get this error.
The Error is the following one:
Error: Cannot find module ‘@playwright/test’ Require stack:
- C:\Users\andre\OneDrive\Documentos\PlaywrightTest\playwright.config.js
- C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\common\transform.js
- C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\common\testType.js
- C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\common\test.js
- C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\reporters\multiplexer.js
- C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\runner\reporters.js
- C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\runner\runner.js
- C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\cli.js
- C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\node_modules\playwright-core\lib\cli\cli.js
- C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\node_modules\playwright-core\cli.js
- C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
at Function.resolveFilename (C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\common\transform.js:173:36)
at Function.Module._load (node:internal/modules/cjs/loader:920:27)
at Module.require (node:internal/modules/cjs/loader:1141:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (C:\Users\andre\OneDrive\Documentos\PlaywrightTest\playwright.config.js:1:35)
at Module._compile (node:internal/modules/cjs/loader:1254:14) at Module.f._compile (C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\utilsBundleImpl.js:16:994) at Module._extensions…js (node:internal/modules/cjs/loader:1308:10) at Object.i.<computed>.ot._extensions.<computed> (C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\utilsBundleImpl.js:16:1010) at Module.load (node:internal/modules/cjs/loader:1117:32) at Function.Module._load (node:internal/modules/cjs/loader:958:12) at Module.require (node:internal/modules/cjs/loader:1141:19) at require (node:internal/modules/cjs/helpers:110:18) at requireOrImport (C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\common\transform.js:154:20) at requireOrImportDefaultObject (C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\common\configLoader.js:78:53) at ConfigLoader.loadConfigFile (C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\common\configLoader.js:54:26) at runTests (C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\cli.js:126:55)
at ji.<anonymous> (C:\Users\andre\AppData\Roaming\npm\node_modules@playwright\test\lib\cli.js:48:7) {
code: ‘MODULE_NOT_FOUND’, requireStack: [ ‘C:\Users\andre\OneDrive\Documentos\PlaywrightTest\playwright.config.js’, ‘C:\Users\andre\AppData\Roaming\npm\node_modules\@playwright\test\lib\common\transform.js’,
‘C:\Users\andre\AppData\Roaming\npm\node_modules\@playwright\test\lib\common\testType.js’,
‘C:\Users\andre\AppData\Roaming\npm\node_modules\@playwright\test\lib\common\test.js’,
‘C:\Users\andre\AppData\Roaming\npm\node_modules\@playwright\test\lib\reporters\multiplexer.js’, ‘C:\Users\andre\AppData\Roaming\npm\node_modules\@playwright\test\lib\runner\reporters.js’,
‘C:\Users\andre\AppData\Roaming\npm\node_modules\@playwright\test\lib\runner\runner.js’,
‘C:\Users\andre\AppData\Roaming\npm\node_modules\@playwright\test\lib\cli.js’, ‘C:\Users\andre\AppData\Roaming\npm\node_modules\@playwright\test\node_modules\playwright-core\lib\cli\cli.js’, ‘C:\Users\andre\AppData\Roaming\npm\node_modules\@playwright\test\node_modules\playwright-core\cli.js’, ‘C:\Users\andre\AppData\Roaming\npm\node_modules\@playwright\test\cli.js’ ] }
// playwright.config.js
**const { defineConfig, devices } = require('@playwright/test');
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();
/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },
/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ..devices['Desktop Chrome'], channel: 'chrome' },
// },
],
/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});**
package.json
{ “name”: “playwrighttest”, “version”: “1.0.0”, “description”: “”, “main”: “index.js”, “scripts”: {}, “keywords”: [], “author”: “”, “license”: “ISC” }
I have tryed a lot of different ways but the issue is that I can’t proceed and will have that error I showed no matter how many I try to reproduce different steps to approach to this issue, if anyone has a suggestion or solution I’ll be happy to hear it
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 17 (3 by maintainers)
I’m having this exact issue upon installing version
1.34.0of playwright. I’ve tried this solution and it either gives me a response similar to the above or this responseI’ve tried to follow the steps listed above. My tests were running normally before upgrading to version
1.34.0of playwrightSame problem here, using yarn, in a project having both
@playwright/testandplaywright, since upgrading to1.34.0.I still have the same issue , I am still stuck, I have deleted node js, reinstalled playwright in various ways, to be honest the playwright dev install steps documentation is not very clear to me, should I just try to install a older version to maybe solve this issue?
@john-cyndx You probably have
"playwright"package installed as well? If so, runnpm uninstall playwright, because you don’t need both.@KunalOjha Yes,
const { chromium } = require('@playwright/test')works equally well.I found that when the config is not in the same folder with the node_modules it can’t find @playwright/test
Removing the “playwright” package does in fact resolve this for me in v1.34, the problem I have is I need to use the chromium module from “playwright”
const { chromium } = require('playwright');so I can’t simply remove it. Is this module importable in @playwright/test?Idk why but when I’ve added
npxto my command it started to work. Without it, I had similar error like you guys. This did not happened on previous version (1.33).EDIT: Ok I’ve needed to remove playwright from devDependencies on my side.