简体   繁体   English

找不到模块“调试”-pkg-exe

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

I made a nodeJS app using puppeteer-extra and some puppeteer-extra-plugins , debugging the source code works just fine.我使用 puppeteer puppeteer-extra和一些 puppeteer puppeteer-extra-plugins制作了一个 nodeJS 应用程序,调试源代码工作得很好。 It also runs OK when I pack it into an .exe file using https://www.npmjs.com/package/pkg .当我使用https://www.npmjs.com/package/pkg将其打包到.exe文件中时,它也可以正常运行。

However, when the.exe is moved to a different directory than the 'output' directory, I'm getting the error但是,当 .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.

I never use the debug module, it must be required internally by some of my dependencies... but how can I handle this error?我从不使用debug模块,我的一些依赖项必须在内部需要它......但我该如何处理这个错误?

I've got these requires我有这些要求

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'));

and my package.json (config for pkg)和我的 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"
    ]
  }

I solved it by changing my requires to我通过改变我的要求来解决它

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

and later, launching the browser setting explicitly the executablePath in puppeteer's options.稍后,在 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)

Note however, that I had to leave out the 'puppeteer-extra-plugin-stealth', because it complained about但是请注意,我不得不省略“puppeteer-extra-plugin-stealth”,因为它抱怨

"A plugin listed 'puppeteer-extra-plugin-stealth/evasions/chrome.runtime' as dependency, which is currently missing. Please install it:" “一个插件将 'puppeteer-extra-plugin-stealth/evasions/chrome.runtime' 列为依赖项,目前缺少。请安装它:”

and adding a pkg/asset as suggestedhere , did not help并按照这里的建议添加一个 pkg/asset ,没有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM