I’m trying to create an executable file from my web scraping application using pkg. My script works fine when running with node, but after building the executable, I get a module not found error.
My main script (app.js):
const path = require('path');
const puppeteerCore = require('puppeteer-extra');
const stealthMode = require('puppeteer-extra-plugin-stealth');
puppeteerCore.use(stealthMode());
// additional functionality here...
The executable builds successfully with pkg .
command, but when I try to run it, I encounter the error message about missing puppeteer module. The only workaround I found is keeping the node_modules directory in the same location as the executable.
I attempted to include dependencies in my package.json configuration:
{
"pkg": {
"assets": "node_modules/**/*.*"
}
}
However, this approach seems to hang indefinitely during the build process. Has anyone encountered this issue before? What’s the proper way to bundle these dependencies into the final executable?
Had this exact problem a few months back. pkg chokes on puppeteer’s native bindings and how it loads modules dynamically. Here’s what fixed it for me: ditch regular puppeteer for puppeteer-core, manually download a specific chromium version, then bundle it as an asset. In your package.json, include just the chromium binary - don’t try to bundle the whole node_modules folder. Point your puppeteer launch options’ executablePath to that bundled chromium binary. The build hangs because pkg tries to include thousands of useless files when you specify all of node_modules. Be picky with your assets config - only grab what puppeteer actually needs.
The hanging happens because pkg tries to process every single file in node_modules - we’re talking thousands of unnecessary files. Here’s a better approach: Use puppeteer-core instead of regular puppeteer so it won’t auto-download chromium. Download chromium manually with puppeteer’s browser fetcher API and stick it in a specific folder. In your pkg config, only bundle the chromium executable and essential runtime files - skip the entire node_modules mess. This cuts build time dramatically and stops the infinite hanging. You’ll need to update your launch options to point at the bundled chromium path using process.cwd() or __dirname.
ya, pkg has issues with puppeteer since it uses dynamic imports. try using puppeteer-core and specify the chromium path yourself, or consider switching to nexe - it manages puppeteer deps much better than pkg.