puppeteer: [Bug]: Pupeeteer does not launch in latest version

Bug description

I am running pupeteer in WSL, ubuntu 20.04. I was able to run puppeteer v 18.1.0 by adding my chrome.exe from Windows to $PATH and launching puppeteer with

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

However in the latest version (18.2.1) I get the error

FAIL src/App.e2e.test.js ● Test suite failed to run

Cannot find module 'puppeteer-core/internal/common/DeviceDescriptors.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

  at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
  at Object.<anonymous> (node_modules/puppeteer/src/puppeteer.ts:18:1)

Puppeteer version

18.2.1

Node.js version

16.17.0

npm version

8.19.2

What operating system are you seeing the problem on?

Windows

Relevant log output

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 23 (2 by maintainers)

Most upvoted comments

I get a similar error with puppeteer@19.7.5: Error: Could not resolve module "puppeteer-core/internal/puppeteer-core.js" (same error as in: https://github.com/Studiosity/grover/issues/182)

In my case, I’m not using jest. I’m calling puppeteer through a parcel plugin (parcel@2.8.3).

Rolling back to:

  • npm install puppeteer@18.1.0 ✅ works
  • npm install puppeteer@18.2.x ❌ fails with a similar (though not equal) error: Error: Could not resolve module "puppeteer-core/internal/common/DeviceDescriptors.js"

Note that puppeteer@18.2.0 (https://github.com/puppeteer/puppeteer/pull/9023) (https://github.com/puppeteer/puppeteer/commit/f42336cf83982332829ca7e14ee48d8676e11545) separated puppeteer and puppeteer-core. Likely a bug was introduced; not directly related to jest or parcel or any other library.

In my humble opinion, this issue is still open.

I am facing the same issue even after upgrading jest to the latest version

"puppeteer": "^19.2.2",
 "@types/jest": "^29.2.3",
 "@types/jest": "^29.2.3",
"jest": "^29.3.1"

Hi, why is it closed? I think the problem is not resolved, it is happenning to me right now. I have react-scripts 5.0.1 too, with puppeteer 19.3.0

npm install puppeteer@18.1.0

Ah, jest-resolver… my old nemesis. Your jest version is too old. It needs exports resolution that was introduced in Node 12. I believe Jest versions >= 28 will work.

I just had the same problem and upgrading Jest from v27 to v29 worked for me, as expected.

So you either have to upgrade Jest to v28 if you can, or downgrade Puppeteer to v18.1.

I’m not sure why this is closed, as this is still a problem on Puppeteer > 18.1.0 (which is out of support) where you are using ESM module loading, e.g. with Puppeteer 18.2.1:

% node -r esm
Welcome to Node.js v20.5.1.
Type ".help" for more information.
> require('puppeteer');
/Users/elliot.smith/projects/opg-pdf-service/node_modules/puppeteer/lib/cjs/puppeteer/puppeteer.js:1
Uncaught Error: Cannot find module 'puppeteer-core/internal/puppeteer-core.js'
Require stack:
- /Users/elliot.smith/projects/opg-pdf-service/node_modules/puppeteer/lib/cjs/puppeteer/puppeteer.js
- <repl>
    at Object.<anonymous> (/Users/elliot.smith/projects/opg-pdf-service/node_modules/puppeteer/lib/cjs/puppeteer/puppeteer.js:33:14)
    at Generator.next (<anonymous>) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/elliot.smith/projects/opg-pdf-service/node_modules/puppeteer/lib/cjs/puppeteer/puppeteer.js',
    '<repl>'
  ]
}
> 

The problem appears to be the -r esm flag, as this works fine for me without it:

% node       
Welcome to Node.js v20.5.1.
Type ".help" for more information.
> require('puppeteer');
{
  connect: [Function: bound bound connect],
  defaultArgs: [Function: bound defaultArgs],
  executablePath: [Function: bound executablePath],
  launch: [Function: bound launch],
  trimCache: [Function: bound trimCache] AsyncFunction,
  WEB_PERMISSION_TO_PROTOCOL_PERMISSION: [Getter],
...

We are using jest, but our version is up to date (29.7.0), and I’m not sure why that would be involved in a straight require('puppeteer'); call anyway.

Not sure, if that is possible. I am using react-script and the latest version 5.0.1 comes along with “jest”: “^27.4.3”, if I see that correctly. So far I was not able to force the usage of v29. I am open for ideas how to upgrade or how to replace jest with something else

Hi! Is there any update on this issue? I am still getting Cannot find module 'puppeteer-core/internal/puppeteer-core.js' on the following config:

"esm": "^3.2.25"
"puppeteer": "^22.0.0"

@townxelliot were you able to find any solution for this?

#_Facing This Issue in in server side(after deploy) - ‘puppeteer’ Working in local machine properly. Any Solution ??

Error: Failed to launch the browser process! /home/abp/.cache/puppeteer/chrome/linux-1108766/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

TROUBLESHOOTING: https://pptr.dev/troubleshooting

at Interface.onClose (/home/abp/abpwedcrmapis-manager/abpwedcrmapis-manager/node_modules/@puppeteer/browsers/lib/cjs/launch.js:262:24)

at Interface.emit (node:events:525:35)
at Interface.emit (node:domain:489:12)
at Interface.close (node:readline:590:8)
at Socket.onend (node:readline:280:10)
at Socket.emit (node:events:525:35)
at Socket.emit (node:domain:489:12)
at endReadableNT (node:internal/streams/readable:1358:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)

npm install puppeteer@18.1.0

It’s working

npm install puppeteer@18.1.0 works for me too.

With puppeteer@20.5.0 i got the error [ERR_PACKAGE_PATH_NOT_EXPORTED]

Now i get: Downloading Chromium r1045629 - 189.9 Mb [===== ] 26% 16.9s

We are using nestjs but we’re not using the latest nestjs version yet. Luckily, jest 28.1.3 works and all our e2e tests passed.

I just copied the jest versions from the latest nestjs app to our current app.

"@types/jest": "28.1.8",
"jest": "28.1.3",
"ts-jest": "28.0.8",