electron报错:Uncaught ReferenceError: process is not defined

完整解决办法:

        在main.js 创建浏览器窗口 webPreferences 中添加:

 nodeIntegration: true,
 contextIsolation: false

        添加完后完整的创建浏览器窗口代码如下: 

const mainWindow = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
            preload: path.join(__dirname, 'preload.js'),
            nodeIntegration: true,
            contextIsolation: false
        },
    })

之后即可在渲染进程的中使用 process 所有方法

猜你喜欢

转载自blog.csdn.net/github_53963510/article/details/130102629