所以我有一個 puppeteer 腳本,我想讓它成為一個 .exe 檔案,其中包含 .exe 檔案中的 node_modules 。
index.js:
const fs = require("fs");
const puppeteer = require("puppeteer-extra");
const StealthPlugin = require("puppeteer-extra-plugin-stealth");
puppeteer.use(StealthPlugin());
code...
當我運行pkg .它時,它會創建 .exe 檔案,但我必須在 node_modules 檔案夾之外運行它才能運行它而不會出現錯誤" Error: Cannot find module 'puppeteer'"
我也在我的 package.json 上試過這個
"pkg": {
"assets": "node_modules/**/*.*"
},
但是已經過了一個小時左右,什么都沒有創造出來,就像它被凍結了一樣。
任何人都可以幫忙嗎?非常感謝!
uj5u.com熱心網友回復:
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"],
headless: false,
defaultViewport: null
})
并構建使用 npm 腳本,如:
"build": "pkg src/index.js --public --targets node14-win-x64 --out-path dist"
uj5u.com熱心網友回復:
嘗試在控制臺中輸入:npm install puppeteer
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/512266.html
標籤:javascript节点.js网页抓取傀儡师可执行程序
