系统相关
首页 > 系统相关> > Electron常见问题 39 - 渲染进程报 require() is not undefined 的解决方法

Electron常见问题 39 - 渲染进程报 require() is not undefined 的解决方法

作者:互联网

目录

问题

解决


PS:《Electron实战》系列-总览 

问题

Electron渲染进程经常会需要引入一些Electron功能模块,比如remote、electron等,有时在导入的时候,会遇到报 require() is not undefined 的问题。

类似报错信息如下:

解决

需要我们在创建渲染窗口的时候,允许集成node.js功能,即
nodeIntegration: true

 

代码实例:

app.on('ready', function(){
	mainWindow = new BrowerWindow({
		height: 300,
		width: 400,

		webPreferences: {
			nodeIntegration: false // 改为true 即可
		}
	})
})

 

标签:39,常见问题,undefined,渲染,require,Electron,nodeIntegration,true
来源: https://blog.51cto.com/u_14832233/2988692