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]: '_projectRoot is undefined. Unable to create a BrowserFetcher.' ( v18.0.4 ) #8999

Closed
cenfun opened this issue Sep 22, 2022 · 6 comments · Fixed by #9079 or #9115
Closed

[Bug]: '_projectRoot is undefined. Unable to create a BrowserFetcher.' ( v18.0.4 ) #8999

cenfun opened this issue Sep 22, 2022 · 6 comments · Fixed by #9079 or #9115

Comments

@cenfun
Copy link

cenfun commented Sep 22, 2022

Bug description

Steps to reproduce the problem:

const puppeteer = require('puppeteer-core');
const browserFetcher = puppeteer.createBrowserFetcher({
        path: 'to-my-path'
    });

throw a error:
node_modules\puppeteer-core\lib\cjs\puppeteer\node\Puppeteer.js:206
throw new Error('_projectRoot is undefined. Unable to create a BrowserFetcher.');
^
Error: _projectRoot is undefined. Unable to create a BrowserFetcher.

API createBrowserFetcher broken, it's works on previous version

Puppeteer version

v18.0.4

Node.js version

v16.17.0

npm version

8.18.0

What operating system are you seeing the problem on?

Windows

Relevant log output

No response

@cenfun cenfun added the bug label Sep 22, 2022
@jrandolf
Copy link
Contributor

See #8919

@jrandolf jrandolf closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2022
@jtymes
Copy link

jtymes commented Sep 29, 2022

I am running into this issue. I am using puppeteer-core only to use its BrowserFetcher to download a known-good revision. As it stands right now, the change introduced in #8907 completely breaks the createBrowserFetcher functionality with puppeteer-core, because _projectRoot will always be undefined. I don't think #8919 offers a solution for that.

One way to fix this could be if path is being passed in the FetcherOptions, it should skip the check on _projectRoot.

@jrandolf
Copy link
Contributor

jrandolf commented Sep 29, 2022

Could you try puppeteer instead of puppeteer-core?

[EDIT]: Scratch that. I assume you are looking to just have the launcher as a separate API. There are some discussions regarding this. If all goes well, it should be come a separate API this quarter. We will see.

@jrandolf jrandolf reopened this Sep 29, 2022
@jtymes
Copy link

jtymes commented Sep 29, 2022

We likely can switch to puppeteer, with a bit of additional configuration. It still leaves puppeteer-core with a broken createBrowserFetcher function that comes back as part of the PuppeteerNode class. If that's the intent, I think it should at least be documented.

@cenfun
Copy link
Author

cenfun commented Sep 30, 2022

thanks @jrandolf
Here's some background
Why puppeteer-core, because we don't want to download chromium when running "npm install", and the chromium size is very large (400M unzipped)
Why createBrowserFetcher, because we want to download chromium to a different directory like user directory but not node_modules, so it can be cached
So puppeteer-core + createBrowserFetcher can solve these usage scenarios very well, but it is broken now
However we can directly call BrowserFetcher to solve it

//fix '_projectRoot is undefined. Unable to create a BrowserFetcher.'
const { BrowserFetcher } = require('puppeteer-core/lib/cjs/puppeteer/node/BrowserFetcher.js');
const createBrowserFetcher = (options) => {
    return new BrowserFetcher('', options);
};
// instead of puppeteer.createBrowserFetcher()

It's just that BrowserFetcher is not a public API, we still hope to fix the public API createBrowserFetcher, thanks again.

jrandolf added a commit that referenced this issue Oct 10, 2022
…9079)

This PR deprecates the `createBrowserFetcher` API and requests users to
import the `BrowserFetcher` directly.

Fixed: #8999
This was referenced Oct 24, 2022
@bm2ilabs
Copy link

Just remove node_modules/puppeteer-core/ if you are using puppeteer-extra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment