Steps to reproduce the problem:
- I installed pupeteer using npm i puppeteer (using WSL ubuntu)
- When I try to load pupeteer in a simple test (
import puppeteer from "puppeteer";
) I get the errorCannot find module 'puppeteer-core/internal/common/Device.js' from 'node_modules/puppeteer/lib/cjs/puppeteer/puppeteer.js'
Any ideas what the issue is?
Pupeteer version: 19.0.0
Node.js version; 16.17.0
npm version: 8.19.2
Script example:
import puppeteer from "puppeteer";
describe("App.js", () => {
let browser;
beforeAll(async () => {
browser = await puppeteer.launch();
});
afterAll(() => browser.close());
});
log output:
FAIL src/App.e2e.test.js ● Test suite failed to run
Cannot find module 'puppeteer-core/internal/common/Device.js' from 'node_modules/puppeteer/lib/cjs/puppeteer/puppeteer.js' Require stack: node_modules/puppeteer/lib/cjs/puppeteer/puppeteer.js src/App.e2e.test.js > 1 | import puppeteer from "puppeteer"; | ^ 2 | 3 | describe("App.js", () => { 4 | let browser; at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11) at Object.<anonymous> (node_modules/puppeteer/src/puppeteer.ts:18:1) at Object.<anonymous> (src/App.e2e.test.js:1:1) at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13) at runJest (node_modules/@jest/core/build/runJest.js:404:19)
Test Suites: 1 failed, 1 total
2
Answers
I was able to fix it with:
Then adding chrome.exe from Windows to my $PATH
And changing the test to
I had a similar issue on MacOS regarding a missing puppeteer-core/internal module except the error message I received was:
I was able to fix it by just rolling back versions of both puppeteer and jest.