错误一:Uncaught ReferenceError: process is not defined
解决方案:
在 .electron-vue文件夹下的 webpack.renderer.config.js文件中修改如下图所示代码:
在 src文件夹下的 index.ejs文件中修改如下图所示代码:
这个错误可以在github上找到相关issue及解决方案:Webpack ReferenceError: process is not defined
#871
可以找到以下截图部分:
错误二:Uncaught ReferenceError: require is not defined 和 Uncaught ReferenceError: module is not defined
解决方案:
在src=》main=》index.js文件中添加代码:
v12.x.x版本之前:
webPreferences: {
nodeIntegration: true,
}
v12.x.x版本:
webPreferences: {
nodeIntegration: true,
contextIsolation: false, //新增行
}
这个错误可以在github上找到相关issue及解决方案:‘require’ is not defined in Electron v12.0.0 in renderer process
#28034
可以找到以下截图部分:
错误三:Uncaught TypeError: Cannot read property ‘app’ of undefined
解决方案:
在src=》main=》index.js文件中添加代码:
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true, //新增行
}