Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'puppeteer-core/internal/puppeteer-core.js #182

Closed
nicks6853 opened this issue Feb 22, 2023 · 5 comments
Closed

Cannot find module 'puppeteer-core/internal/puppeteer-core.js #182

nicks6853 opened this issue Feb 22, 2023 · 5 comments

Comments

@nicks6853
Copy link

nicks6853 commented Feb 22, 2023

Hello,

I am attempting to use Grover in a Rails project but am encountering this error.

Cannot find module 'puppeteer-core/internal/puppeteer-core.js'. You need to add it to 'project-folder/package.json' and run 'npm install'

I am using the following:

  • grover 1.1.4
  • puppeteer 19.7.2
  • ruby 2.7.2
  • Rails 7.0.4
  • Node 18.14.2 (also used 16.18.0 at some point but that didn't work either)
  • npm 9.5.0

Here is my package.json

{
  "name": "project",
  "version": "1.0.0",
  "description": "This README would normally document whatever steps are necessary to get the application up and running.",
  "main": "index.js",
  "directories": {
    "lib": "lib",
    "test": "test"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "puppeteer": "^19.7.2"
  }
}

Here is grover from my Gemfile:

gem "grover", "1.1.4"

I use Grover in the following way:

format.pdf do
  html = render_to_string(
    "pdf/information_sheet",
    layout: false,
    formats: [:html],
    # disable_smart_shrinking: true,
    # viewport_size: "1280x1024",
  )
  pdf = Grover.new(
    html,
    format: "A4",
    print_background: true,
    raise_on_request_failure: true,
    debug: true,
    launch_args: ["--ignore-certificate-errors"],
  ).to_pdf
  send_data(pdf, filename: "InformationSheet-#{DateTime.now.strftime("%F-%T")}.pdf", type: "application/pdf", disposition: :inline)
end

I tried installing puppeteer-core and that didn't work.
The only way I was able to get it to run was by using 18.1 which is not supported anymore.

Does anyone have any input on this? Seems like any version of puppeteer (18.2.x and higher) throws this error.

@abrom
Copy link
Contributor

abrom commented Feb 24, 2023

Hmm interesting problem. The only thing that stands out to me is the path in the error message. Specifically

project-folder/package.json

"normally" that would just be package.json (using Dir.pwd) but if it is including some other path in there, and you're not specifically defining the root location of the package.json file with the root_path option, then it suggests there's something funny about how your environment is setup?! I also can't explain why reverting to an earlier Puppeteer version would fix it for you. Can you tell me what Dir.pwd is (relative to your project root)? Can you try specifying the root_path option with the path of your package.json file?

@nicks6853
Copy link
Author

The project-folder was just a placeholder for the actual path to the root of my rails project. It was long so I took it out but this is it: /var/www/wwwruby/riviera2022/package.json

I found a similar issue in the puppeteer project and the only answer from that thread that worked for me was to revert to 18. Any version after 18.1 throws this error.

@abrom
Copy link
Contributor

abrom commented Mar 2, 2023

That's really odd! I use 19.6.3 with no issues (not that it helps you..)

That issue suggests that the issue is jest related. You don't by chance have jest in your package.json but clipped it for brevity?

I'd be interested to see more of the Node call-stack surrounding the error. Can you fork the project, then modify this line https://github.com/Studiosity/grover/blob/main/lib/grover/processor.rb#L54 to:

raise Grover::Error, error_message

(ie just remove the unless package_name guard statement.)

Then try call to grover again. That will dump the raw Node call-stack and should tell us if something is getting "in the way" (like in the puppeteer issue you referenced the issue being jest-resolve).

@CeceliaYu
Copy link

i'm using jasmine + grunt and getting similar error:

 Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './internal/puppeteer-core.js' is not defined by "exports" in <<node_module_path>>/grunt-contrib-jasmine/node_modules/puppeteer-core/package.json

@abrom
Copy link
Contributor

abrom commented Mar 9, 2024

Doesn't appear to be any movement on this. Feel free to re-open if you need to/can reply to my questions 😄

@abrom abrom closed this as completed Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants