You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron打包为exe后无法找到puppeteer-extra-plugin-stealth模块

搞定打包exe后找不到puppeteer-extra-plugin-stealth模块的问题

开发环境用npm start跑没问题,打包成exe就报找不到puppeteer-extra-plugin-stealth/evasions/chrome.app?这是因为pkg打包工具没法自动识别stealth插件内部动态加载的反检测模块,导致这些文件没被塞进最终的exe里。

给你两个靠谱的解决办法:

办法一:修改pkg配置,强制打包所有相关文件

直接改package.json里的pkg配置,加上assets字段,把stealth插件所有反检测模块都包含进去:

"pkg": {
  "scripts": [
    "node_modules/puppeteer/lib/*.js",
    "node_modules/puppeteer-extra-plugin-stealth/**/*.js"
  ],
  "assets": [
    "node_modules/puppeteer-extra-plugin-stealth/evasions/**/*"
  ]
}

这样配置后,pkg就会把evasions目录下所有文件都打包,不管是不是动态加载的。

办法二:手动导入需要的反检测模块

不想改配置的话,就手动把需要的模块静态导入,让pkg能检测到这些依赖:

import PuppeteerExtra from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
// 把报错的模块和其他常用反检测模块手动导入
import chromeAppEvasion from 'puppeteer-extra-plugin-stealth/evasions/chrome.app';
import chromeRuntimeEvasion from 'puppeteer-extra-plugin-stealth/evasions/chrome.runtime';
import navigatorVendorEvasion from 'puppeteer-extra-plugin-stealth/evasions/navigator.vendor';

const stealth = StealthPlugin();
// 确保这些模块启用(默认本来就启用,这里主要是让pkg打包它们)
stealth.enabledEvasions.add('chrome.app');
stealth.enabledEvasions.add('chrome.runtime');
stealth.enabledEvasions.add('navigator.vendor');

PuppeteerExtra.use(stealth);

静态导入后,pkg的依赖分析就能抓到这些模块,不会漏掉了。

额外小提示

打包前可以先清一下依赖缓存,避免旧缓存搞事情:

rm -rf node_modules package-lock.json
npm install
npm run package

内容的提问来源于stack exchange,提问作者Hanh Nguyen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 22:07:34