Reputation: 63
so I have a puppeteer script and I want to make it a .exe file that includes node_modules within the .exe file.
index.js:
const fs = require("fs");
const puppeteer = require("puppeteer-extra");
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
puppeteer.use(StealthPlugin());
code...
When I run pkg .
it creates the .exe files but I have to run it besides the node_modules folder to be able to run it without having the error " Error: Cannot find module 'puppeteer'"
I also tried this on my package.json
"pkg": {
"assets": "node_modules/**/*.*"
},
But it has been like an hour or so, and nothing has been created, it's like it has frozen.
Anyone can help? Thanks a lot!
Upvotes: 3
Views: 3263
Reputation: 587
const puppeteer = require("puppeteer-extra");
const isPkg = typeof process.pkg !== 'undefined';
const chromiumExecutablePath = isPkg
? puppeteer.executablePath().replace(
/^.*?\/node_modules\/puppeteer\/\.local-chromium/,
path.join(path.dirname(process.execPath), '.local-chromium')
) : puppeteer.executablePath()
);
const browser = await puppeteer.launch({
executablePath: chromiumExecutablePath,
args: [
"--start-maximized",
"--no-sandbox",
],
headless: false,
defaultViewport: null
})
And to build use npm script like:
"build": "pkg src/index.js --public --targets node14-win-x64 --out-path dist"
Upvotes: 2