请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

TypeError: electron.BrowserWindow.addDevToolsExtension is not a function

使用devtron 工具的时候报错
图片描述

const {app, BrowserWindow, ipcMain} = require('electron')
const path = require('path')
app.on("ready", () => {
  require("devtron").install();
  const mainWindow = new BrowserWindow({
    height: 1200,
    webPreferences: { // 确定webPage的属性
      nodeIntegration: true, // 表示可以在electron中使用node
      preload: path.join(__dirname, "preload.js"),
    },
    width: 1600
  });
  mainWindow.loadFile("index.html");
  mainWindow.webContents.openDevTools();
  ipcMain.on("message", (event, arg) => {
    console.log(arg);
  });
});

经过本人测试,是require("devtron").install();这条语句的问题,一旦加上,则会报之前的错,不加,则运行成功

正在回答

2回答

同学你好 刚刚使用了和你一摸一样的源代码进行测试 发现没有这个错误 可否告知你 electron 的版本?我的版本是 7.1.1  我还发现你的 devtron路径在 node_modules 是带有下划线的目录 _devtron 而我安装的是没有下划线的 devtron,请你重新安装一下 devtron 试试。

npm install --save-dev devtron

1 回复 有任何疑惑可以回复我~
  • 提问者 幽辰 #1
    我重新安装了下包就好了,不知道之前干了什么可能安装错包了
    回复 有任何疑惑可以回复我~ 2020-06-04 00:53:49
  • 老师您好,
    
    "devtron": "^1.4.0",
     "electron": "^16.0.2",
    同样的错误,重新下载 devtron也没用。
    老师辛苦看一下?
    回复 有任何疑惑可以回复我~ 2021-12-10 09:41:36
  • 张轩 回复 慕仙8092207 #3
    同学你好 devtron 已经处于不维护的状态了 新版 electron 是不支持的,只能用 electron5 版本才能兼容,我建议你不要使用这个插件啦
    回复 有任何疑惑可以回复我~ 2021-12-10 10:08:36
aoyeebay 2020-07-02 13:43:40
Installing Devtron from C:\Users\ceshi\electron-quick-start\node_modules\devtron
(electron) 'BrowserWindow.getDevToolsExtensions' is deprecated and will be removed. Please use 'session.getAllExtensions' instead.
(electron) 'BrowserWindow.addDevToolsExtension' is deprecated and will be removed. Please use 'session.loadExtension' instead.
(node:13128) UnhandledPromiseRejectionWarning: Error: Loading extension at C:\Users\aoyeebay\electron-quick-start\node_modules\devtron failed with: The 'manifest_version' key must be present and set to 2 (without quotes). See developer.chrome.com/extensions/manifestVersion.html for details.
(node:13128) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13128) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

老师,我的electron版本9.0.5,Devtron版本1.4.0,截至目前最新版吧,然后用了您课程上的代码require("devtron").install() 到这一句报错,并且chrome开发工具里没有多一个Devtron,是不是这个插件不更新了?

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号