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

Running esbuild-bundled script crashes with ENOENT (related to vm2) #197

Closed
karlhorky opened this issue Jun 8, 2023 · 3 comments
Closed

Comments

@karlhorky
Copy link

karlhorky commented Jun 8, 2023

Partly related to the original issue in the old repo:

Copying my issue report from puppeteer/puppeteer#10352, since puppeteer-core now depends on proxy-agent and other packages in this repo:


Bug expectation

I expected to be able to bundle my Puppeteer script with esbuild

My esbuild-bundled Puppeteer script failed (see full error output below) because of the transitive dependency on vm2 (via puppeteer-core -> proxy-agent -> pac-proxy-agent -> pac-resolver -> degenerator -> vm2)

$ node abc.mjs
node:fs:601
  handleErrorFromBinding(ctx);
  ^

Error: ENOENT: no such file or directory, open '/home/runner/work/project/project/bridge.js'
    at Object.openSync (node:fs:601:3)
    at Object.readFileSync (node:fs:469:35)
    at ../../node_modules/@puppeteer/browsers/node_modules/vm2/lib/vm.js (file:///home/runner/work/project/project/abc.mjs:52297:66)
    at __require2 (file:///home/runner/work/project/project/abc.mjs:20:50)
    at ../../node_modules/@puppeteer/browsers/node_modules/vm2/lib/main.js (file:///home/runner/work/project/project/abc.mjs:54169:9)
    at __require2 (file:///home/runner/work/project/project/abc.mjs:20:50)
    at ../../node_modules/@puppeteer/browsers/node_modules/vm2/index.js (file:///home/runner/work/project/project/abc.mjs:54197:22)
    at __require2 (file:///home/runner/work/project/project/abc.mjs:20:50)
    at ../../node_modules/@puppeteer/browsers/node_modules/degenerator/dist/index.js (file:///home/runner/work/project/project/abc.mjs:54211:17)
    at __require2 (file:///home/runner/work/project/project/abc.mjs:20:50) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/runner/work/project/project/bridge.js'
}

Node.js v18.16.0

It appears to be related to this current problem with bundling vm2:

Seems like the first version that this happens with is puppeteer-core@20.4.0, which upgraded @puppeteer/browsers from 1.3.0 to 1.4.0, which added proxy-agent.

Minimal, reproducible example

Bundle any Puppeteer script such as the simple script below via esbuild like this:

$ esbuild index.ts --bundle --outfile=abc.mjs --platform=node --target=node18 --format=esm

index.ts

import puppeteer from 'puppeteer'; // TS/ESM are all supported.

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://news.google.com/news/');
  await page.screenshot({path: 'news.png', fullPage: true});
  await browser.close();
})();

Error string

ENOENT: no such file or directory, open '/home/runner/work/project/project/bridge.js'

Puppeteer version

20.5.0

Node version

18.16.0

Package manager

pnpm

Package manager version

8.6.1

Operating system

macOS

@cnlewis3
Copy link

cnlewis3 commented Jun 9, 2023

Just adding that I'm also seeing this when trying to deploy puppeteer v20.4.0 to AWS Lambda, same line of reasoning as mentioned above.

@TooTallNate
Copy link
Owner

The linked vm2 issue at least provides a workaround:

I have to copy these files to dist

But ya, since this is out of the control of these packages, I will close.

@OrKoN
Copy link

OrKoN commented Jul 11, 2023

I saw the following warning: npm WARN deprecated vm2@3.9.19: The library contains critical security issues and should not be used for production! The maintenance of the project has been discontinued. Consider migrating your code to isolated-vm. Will it be difficult to migrate? Perhaps migration will solve this issue too.

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

4 participants