Packaging issues with puppeteer 24.0.0 upgrade using pkg

Hey everyone, I’m having some trouble with pkg after updating puppeteer. I went from version 1.20.0 to 24.0.0 and now my build is failing. Here’s what’s going on:

I’m using this build command:

"scripts": {
    "pre_build_andata": "rm -rf build",
    "_build_andata": "pkg src/startup.js --targets node18-macos-arm64 --output build/andata-helper"
}

When I run it, I get some warnings about Babel parse failing and bytecode issues. I tried adding some config options for pkg scripts and assets, but it didn’t help:

"assets": [
  "*"
],
"scripts": [
  "node_modules/puppeteer/lib/*.js",
  "!node_modules/**/*.d.ts",
  "!../node_modules/**/*.d.ts"
]

Has anyone successfully packaged puppeteer 24.0.0 with pkg? What am I missing here? It worked fine with the old version, but I’m stuck now. Any tips would be super helpful!

yo, had the same headache. try adding ‘–public’ flag to ur pkg command. it fixed it for me. like this:

‘pkg src/startup.js --targets node18-macos-arm64 --public --output build/andata-helper’

Puppeteer 24 has some weird stuff goin on with how it loads things. this flag tells pkg to include more files. mite help!

I encountered a similar issue when upgrading Puppeteer. One solution that worked for me was to use the ‘–no-bytecode’ flag in the pkg command. This prevents pkg from trying to compile bytecode, which can cause issues with newer Puppeteer versions.

Try modifying your build script like this:

"_build_andata": "pkg src/startup.js --targets node18-macos-arm64 --no-bytecode --output build/andata-helper"

Additionally, ensure you’re using the latest version of pkg. Sometimes, older versions struggle with newer Node.js and Puppeteer releases.

If you’re still facing issues, you might need to explicitly include Puppeteer’s dependencies in your pkg configuration. Add this to your package.json:

"pkg": {
  "scripts": ["node_modules/puppeteer/**/*.js"],
  "assets": ["node_modules/puppeteer/**/*"]
}

This ensures all necessary Puppeteer files are included in the packaged application.

I’ve actually run into similar issues when upgrading Puppeteer recently. In my experience, the jump from 1.x to 24.x versions is quite significant and can break packaging.

One thing that worked for me was explicitly including Puppeteer’s browser binary in the pkg assets. Try adding this to your package.json:

"pkg": {
  "assets": [
    "node_modules/puppeteer/.local-chromium/**/*"
  ]
}

Also, make sure you’re using the latest version of pkg, as older versions may struggle with newer Node.js and Puppeteer releases.

If that doesn’t solve it, you might need to look into using a custom Chromium binary and telling Puppeteer where to find it at runtime. It’s a bit more complex, but it gives you more control over the packaging process.

Hope this helps! Let me know if you need any clarification on these steps.