Search code examples
jestjspuppeteerreact-testing-library

Cannot find module 'puppeteer-core/internal/puppeteer-core.js' from 'puppeteer.js'


So I am trying to use the latest version of puppeteer (21.3.8) to use for PDF generation from HTML/CSS in my React program. The issue I've been facing is how certain elements within the HTML/CSS misbehave with tables when in "pritning mode" (WIN+P / CMD+P), e.g. page break at incorrect places.

By using the latest version puppeteer@21.3.8, I receive the following when trying to run tests that work with versions that are no longer supported (<19.4.0):

Cannot find module 'puppeteer-core/internal/puppeteer-core.js' from 'puppeteer.js'

I am using jest version: jest: ^24.9.0 and React-testing-library!

I don't really want to rollback the version of puppeteer since it will break my PDF generation. If anyone know of any fix or suggestions, please let me know. Thanks! :)

What I've tried:

  • Reverting version of puppeteer to 18.1.0, making the tests work but the functionality not work

  • Installing version in-between 18.1.0 and 21.3.8, making either functionality work and tests not working and vice versa.

  • Tried packages such as puppeteer-extra and played around with executablePath(), but without success.


Solution

  • One way to fix this from what I found was to update jest to the latest version. As of writing this, it is

    npm i jest@29.7.0
    

    Not sure exactly how it solves it but according to my research, jest version >=29 seems to know how to handle the split between puppeteer and puppeteer-core that was made version 18.2.0