簡體   English   中英

找不到模塊“調試”-pkg-exe

[英]Cannot find module 'debug' - pkg - exe

我使用 puppeteer puppeteer-extra和一些 puppeteer puppeteer-extra-plugins制作了一個 nodeJS 應用程序,調試源代碼工作得很好。 當我使用https://www.npmjs.com/package/pkg將其打包到.exe文件中時,它也可以正常運行。

但是,當 .exe 移動到與“輸出”目錄不同的目錄時,出現錯誤

Cannot find module 'debug'
1) If you want to compile the package/file into executable, please pay attention to compilation warnings
 and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable
 and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call
 using process.cwd() or process.execPath.

我從不使用debug模塊,我的一些依賴項必須在內部需要它......但我該如何處理這個錯誤?

我有這些要求

const puppeteer = require(path.join(process.cwd(), 'dependencies', 'puppeteer-extra'));
const StealthPlugin = require(path.join(process.cwd(), 'dependencies', 'puppeteer-extra-plugin-stealth'));
const RecaptchaPlugin = require(path.join(process.cwd(), 'dependencies', 'puppeteer-extra-plugin-recaptcha'));
const UserPrefsPlugin = require(path.join(process.cwd(), 'dependencies', 'puppeteer-extra-plugin-user-preferences'));

和我的 package.json(配置為 pkg)

"pkg": {
    "scripts": [
      "node_modules/puppeteer/lib/*.js"
    ],
    "assets": [
      "./node_modules/@types",
      "./node_modules/typescript/lib/*.d.ts",
      "src/**/*.ts",
      "./tsconfig.json"
    ],
    "targets": [
      "node8-win32"
    ]
  }

我通過改變我的要求來解決它

const puppeteer = require('puppeteer-extra');
const RecaptchaPlugin = require('puppeteer-extra-plugin-recaptcha');
const UserPrefsPlugin = require('puppeteer-extra-plugin-user-preferences');

稍后,在 puppeteer 的選項中顯式啟動瀏覽器設置 executablePath。

const options = {
  headless: false,
  devtools: false,
  args: ['--start-maximized'],
  timeout: 300000,
  downloadPath: path.join(process.env.USERPROFILE, 'Downloads'),
  askDownload: false,
  executablePath: path.join(process.cwd(), "puppeteer-extra", 
  "node_modules\\puppeteer\\.local-chromium\\win64-722234\\chrome-win\\chrome.exe")
}
await puppeteer.launch(this.options)

但是請注意,我不得不省略“puppeteer-extra-plugin-stealth”,因為它抱怨

“一個插件將 'puppeteer-extra-plugin-stealth/evasions/chrome.runtime' 列為依賴項,目前缺少。請安裝它:”

並按照這里的建議添加一個 pkg/asset ,沒有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM