为什么crashReporter在Electron中未定义?

时间:2017-06-28 21:55:17

标签: javascript electron

我最近升级到Electron版本1.6.11,现在当我运行npm start命令时,出现以下错误:

enter image description here

main.js文件的顶部如下所示:

const {app, BrowserWindow, ipcMain, crashReporter} = require('electron');
const path = require('path');

crashReporter.start({
    productName: 'MyCo',
    companyName: 'MyCo, Inc.',
    submitURL: 'https://myco.co/fake-url-to-submit',
    uploadToServer: true
});

app.on('window-all-closed', function() {
  if (process.platform != 'darwin') {
    app.quit();
  }
});

以下是我的package.json文件的内容:

{
  "name": "MyApp",
  "productName": "MyApp",
  "version": "0.0.1",
  "main": "main.js",
  "repository": "https://github.com/zackshapiro/myApp",
  "devDependencies": {
    "babel-core": "^6.7.2",
    "babel-eslint": "^7.1.1",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-react": "^6.3.13",
    "babel-preset-stage-3": "^6.17.0",
    "css-loader": "^0.23.1",
    "electron": "^1.6.11",
    "electron-packager": "^8.7.1",
    "electron-rebuild": "^1.1.3",
    "eslint": "^3.13.1",
    "eslint-loader": "^1.6.1",
    "eslint-plugin-react": "^6.9.0",
    "file-loader": "^0.10.1",
    "node-libs-browser": "^1.0.0",
    "node-sass": "^4.2.0",
    "sass-loader": "^4.1.1",
    "style-loader": "^0.13.0",
    "webpack": "^2.6.1",
    "webpack-dev-server": "^2.4.4"
  },
  "scripts": {
    "start": "./node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron .",
    "watch": "./node_modules/.bin/webpack-dev-server",
    "electron-rebuild": "./node_modules/.bin/electron-rebuild"
  },
  "dependencies": {
    "babel-polyfill": "^6.22.0",
    "electron-context-menu": "^0.8.0",
    "electron-prebuilt": "^0.37.2",
    "gl-react": "^2.2.9",
    "gl-react-hue-rotate": "^1.1.0",
    "isomorphic-fetch": "^2.2.1",
    "rc-slider": "^6.1.0",
    "react": "15.4.2",
    "react-dnd": "^2.2.4",
    "react-dnd-html5-backend": "^2.2.4",
    "react-dom": "15.4.2",
    "react-redux": "^5.0.2",
    "react-router": "^4.1.1",
    "react-router-dom": "^4.1.1",
    "react-router-redux": "^5.0.0-alpha.6",
    "redux": "^3.6.0",
    "redux-saga": "^0.14.3",
    "tinycolor2": "^1.4.1"
  }
}

如何解决此问题并让crashReporter正常工作?

1 个答案:

答案 0 :(得分:1)

您的start脚本错误 - 您正在尝试使用已过时的electron-prebuilt,但您可能忘记将其从计算机上卸载,因此它仍然有效。它目前在您的devDependencies中,但已被弃用,自2016年以来一直未得到支持。请将其删除:

npm uninstall --save-dev electron-prebuilt

electron-prebuilt未附带crashReporter因此在您尝试导入时未定义。

您应该使用electron附带的最新crashReporter。为此,请将脚本更改为(如果已在本地安装):

"start": "./node_modules/.bin/electron ."

这将使用electron代替electron-prebuilt,它应该可以正常工作。