-
Notifications
You must be signed in to change notification settings - Fork 9k
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]: esbuild-bundled script crashes with ENOENT (related to vm2
?)
#10352
Comments
vm2
?)
This issue was not reproducible. Please check that your example runs locally and the following:
Once the above checks are satisfied, please edit your issue with the changes and we will |
Having this same issue when trying to deploy to our AWS Lambda. Worked fine with previous versions, but getting a |
Hey I tried to reproduce but I keep getting this error:
Would it be possible to provide a repo with the issue you are seeing? |
To be clear, you're seeing the following error? $ node abc.mjs
file:///Users/k/p/puppeteer-esbuild-vm2/abc.mjs:13
throw new Error('Dynamic require of "' + x + '" is not supported');
^
Error: Dynamic require of "stream" is not supported
at file:///Users/k/p/puppeteer-esbuild-vm2/abc.mjs:13:9
at node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/stream.js (file:///Users/k/p/puppeteer-esbuild-vm2/abc.mjs:11585:22)
at __require2 (file:///Users/k/p/puppeteer-esbuild-vm2/abc.mjs:19:50)
at node_modules/.pnpm/ws@8.13.0/node_modules/ws/wrapper.mjs (file:///Users/k/p/puppeteer-esbuild-vm2/abc.mjs:15071:29)
at __init (file:///Users/k/p/puppeteer-esbuild-vm2/abc.mjs:16:56)
at node_modules/.pnpm/puppeteer-core@20.4.0_typescript@5.1.3/node_modules/puppeteer-core/lib/esm/puppeteer/common/NodeWebSocketTransport.js (file:///Users/k/p/puppeteer-esbuild-vm2/abc.mjs:15096:5)
at __init (file:///Users/k/p/puppeteer-esbuild-vm2/abc.mjs:16:56)
at file:///Users/k/p/puppeteer-esbuild-vm2/abc.mjs:79315:1
at ModuleJob.run (node:internal/modules/esm/module_job:194:25) I'm working on making a reproduction repo that shows the |
Sorry, this error was actually related to globals not available in Here's a new reproduction (run https://github.com/karlhorky/puppeteer-esbuild-vm2-reproduction |
As you pointed out the problem is in the |
|
The issue is that
|
@karlhorky I believe it is the issue https://github.com/patriksimek/vm2/blob/1663f231ec02db473ed5b743e3b91b8a2ffc7982/lib/vm.js#L145 the __dirname in the esbuild-produced bundle appears to be incorrect |
yeah it expects the node_modules to be around and the __dirname to point to the vm2's lib folder. |
The way that we're bundling + deploying, we do not have a So anyone taking a similar approach with their bundling will also have this issue |
Workaround 1A possible (ugly) workaround would be to require all of your users who want to bundle to copy the necessary files out from Puppeteer's transitive dependency
|
But maybe Puppeteer could do something about this so that bundling is zero-config 🤞 |
@karlhorky you can probably work around it by specifying |
Workaround 2Confirmed, using the esbuild "build": "esbuild index.ts --bundle --external:vm2 --outfile=abc.mjs --platform=node --target=node18 --format=esm --banner:js=\"import { createRequire as createRequire99 } from 'module'; import { dirname as dirname99 } from 'node:path'; import { fileURLToPath as fileURLToPath99 } from 'node:url'; const __filename = fileURLToPath99(import.meta.url); const __dirname = dirname99(__filename); const require = createRequire99(import.meta.url);\"" Description of the
I guess this may not work for everyone, but represents a simpler workaround for the |
Having the exact same issue, we are using node npx nx run api:serve |
How we solve was changing |
I've also encountered the same issue and have tried both methods. It seems that this problem occurs in versions above 20.0. Temporarily switching to version 19.10.0 seems to work for now. |
A more straightforward approach if you use CopyPlugin in your webpack is
|
fixed via #10548 |
Nice, thanks for circling back around here @OrKoN! 🙌 (and for making the PR) I can confirm that building with
|
thanks so much! |
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 onvm2
(viapuppeteer-core
->proxy-agent
->pac-proxy-agent
->pac-resolver
->degenerator
->vm2
)It appears to be related to this current problem with bundling
vm2
:This has also been reported in the repos for
proxy-agent
:esbuild
-bundled script crashes withENOENT
(related tovm2
) TooTallNate/proxy-agents#197Seems like the first version that this happens with is
puppeteer-core@20.4.0
, which upgraded@puppeteer/browsers
from1.3.0
to1.4.0
, which addedproxy-agent
.Bug behavior
Minimal, reproducible example
Bundle any Puppeteer script such as the simple script below via
esbuild
like this:index.ts
Error string
ENOENT: no such file or directory, open '/home/runner/work/project/project/bridge.js'
Puppeteer configuration
No response
Puppeteer version
20.5.0
Node version
18.16.0
Package manager
pnpm
Package manager version
8.6.1
Operating system
macOS
The text was updated successfully, but these errors were encountered: