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

[Bug]: puppeteer-core trying to load package.json "Cannot find package directory" #8896

Closed
lennybakkalian opened this issue Sep 2, 2022 · 5 comments · Fixed by #8907 or #8904
Closed
Assignees

Comments

@lennybakkalian
Copy link

lennybakkalian commented Sep 2, 2022

Bug description

Steps to reproduce the problem:

  1. create project with puppeteer-core dependency
  2. build app and start without package.json in folder

why does this error occur? I have debugged the app and for reasons unknown to me, puppeteer tried to load a package.json. It can not be that you should push the package.json with a deployment, right?

if i build and run the app locally it works, but only because the package.json exists.

Puppeteer version

16.2.0

Node.js version

16.10.0

npm version

7.24.0

What operating system are you seeing the problem on?

Linux

Relevant log output

Error: Cannot find package directory
    at exports.getPackageDirectory (/app/main.js:2:1175154)
    at exports.initializePuppeteer (/app/main.js:2:1115914)
    at Object.2056 (/app/main.js:2:1172454)
    at __webpack_require__ (/app/main.js:2:1730339)
    at Object.7157 (/app/main.js:2:578353)
    at __webpack_require__ (/app/main.js:2:1730339)
    at Object.5052 (/app/main.js:2:575175)
    at __webpack_require__ (/app/main.js:2:1730339)
    at Object.6828 (/app/main.js:2:574225)
    at __webpack_require__ (/app/main.js:2:1730339)
@OrKoN
Copy link
Collaborator

OrKoN commented Sep 3, 2022

Puppeteer uses package.json to locate the Puppeteer's installation directory because it's where the downloaded browser binaries are stored by Puppeteer. If this functionality is not required for you, you can use the puppeteer-core package.

@OrKoN OrKoN closed this as not planned Won't fix, can't repro, duplicate, stale Sep 3, 2022
@imtiger
Copy link

imtiger commented Sep 3, 2022

i pack an electron app using puppeteer,in development environment ,it works. but when the app runs at another computer,it not works.the error info in the picture.
WechatIMG6204

@lennybakkalian
Copy link
Author

lennybakkalian commented Sep 4, 2022

@OrKoN unfortunately the same error also occurs with puppeteer-core.

I haven't read through the code much, but it looks like in puppeteer-core.ts the method initializePuppeteer is called, where getPackageDirectory is called, which leads to this error.

A possible fix could be that getPackageDirectory is only called when packageName != "puppeteer-core".

const isPuppeteerCore = packageName === 'puppeteer-core';
const puppeteerRootDirectory = isPuppeteerCore ? undefined : getPackageDirectory(rootDirname);

@imtiger posting screenshots or pictures of error messages is a sin.

@OrKoN OrKoN reopened this Sep 5, 2022
@OrKoN
Copy link
Collaborator

OrKoN commented Sep 5, 2022

Oh, I was under impression, that puppeteer-core would not need this logic at all. Let me double check, if there is no real need, this might be a bug.

@OrKoN OrKoN self-assigned this Sep 5, 2022
@OrKoN OrKoN added the confirmed label Sep 5, 2022
@imtiger
Copy link

imtiger commented Sep 5, 2022

image

this is my package.json dependencies,i use puppeteer not puppeteer-core.

https://github.com/puppeteer/puppeteer/blob/eb6cea4f575467beca9a952ddf3045b7a38c44d5/src/util/getPackageDirectory.ts

this method throws the exception.

@lennybakkalian lennybakkalian changed the title [Bug]: App crash after nx build "Cannot find package directory". Why does it try to find/load a package.json? [Bug]: puppeteer-core trying to load package.json "Cannot find package directory" Sep 5, 2022
OrKoN added a commit that referenced this issue Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants