未下载Chromium版本。在Electron build中的Launcher.launch中运行“ npm install”或“ yarn install”

时间:2018-10-23 03:13:23

标签: node.js electron puppeteer

我的项目是一个桌面Electron应用程序,单击该应用程序会刮擦一个网站。很简单。

我的项目在本地运行正常(当然),但是当我运行npm run package-win并创建Windows生产应用程序时,我相信当puppeteer尝试启动浏览器时会出现错误。

我仅在针对Windows构建时得到此信息。可以在我的Mac上构建,并且没有错误...

Chromium revision is not downloaded. Run "npm install" or "yarn install"  at Launcher.launch

我尝试删除package.lock,node_modules文件夹,并且当然按照建议运行npm install。我认为这与版本控制有关吗?这是我的package.json文件:

{
  "name": "my-project",
  "version": "1.0.0",
  "description": "My project description.",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "package-win": "electron-packager . my-project --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"My Project\""
  },
  "license": "CC0-1.0",
  "devDependencies": {
    "electron": "^2.0.12",
    "electron-packager": "^12.2.0"
  },
  "dependencies": {
    "electron-json-storage": "^4.1.4",
    "nodemailer": "^4.6.7",
    "puppeteer": "^1.8.0"
  }
}

我可以说我的try catch失败了,因为错误消息来自catch,所以此块中的某些内容失败了,但仅限于生产版本:

  async scrape(url) {
      try {
        // Launch & Setup browser
        this.browser = await puppeteer.launch({
          args: ["--no-sandbox"],
          headless: true
        });
        this.page = await this.browser.newPage();
        await this.page.setViewport({
          width: 1920,
          height: 926
        });
        this.page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36');

        await this.page.goto(url);
        await this.page.waitForSelector('ul.rows');

        // Get all the listings on the page
        this.listings_array = await this.get_DOM_elements_from_page();
        console.log(this.listings_array);

      } catch (err) {
        console.log('SOMETHING WENT WRONG', err);
      }
    }

此函数在类内部。这就是为什么引用this的原因。我将浏览器,页面和其他内容存储在刮板实例上。

1 个答案:

答案 0 :(得分:0)

"pkg": "rm -rf ./pkg && pkg -t node8-macos-x64 --out-path pkg .",
"postpkg": "mkdir -p ./pkg/node_modules/puppeteer && cp -R ./node_modules/puppeteer/.local-chromium ./pkg/node_modules/puppeteer"

将此添加到您的package.json