skip to Main Content

Steps to reproduce the problem:

  1. I installed pupeteer using npm i puppeteer (using WSL ubuntu)
  2. When I try to load pupeteer in a simple test (import puppeteer from "puppeteer";) I get the error Cannot 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


  1. Chosen as BEST ANSWER

    I was able to fix it with:

    npm i [email protected]

    Then adding chrome.exe from Windows to my $PATH

    And changing the test to

    browser = await puppeteer.launch({ 
          executablePath: 'chrome.exe', 
          headless: true,
          args: ['--no-sandbox', '--disable-setuid-sandbox']
        });
    

  2. I had a similar issue on MacOS regarding a missing puppeteer-core/internal module except the error message I received was:

    Cannot find module 'puppeteer-core/internal/puppeteer-core.js' from 'puppeteer.js'
    
          at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)
          at Object.<anonymous> (node_modules/puppeteer/lib/cjs/puppeteer/puppeteer.js:33:14)
    

    I was able to fix it by just rolling back versions of both puppeteer and jest.

    npm install [email protected]
    npm install [email protected]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search