我正在制作一个需要授予对文件系统(fs)模块访问权限的应用程序,但是即使nodeIntegration启用了渲染器,也会出现此错误:
Uncaught ReferenceError: require is not defined
Run Code Online (Sandbox Code Playgroud)
我可以找到的所有类似问题都有一个解决方案,要求他们打开nodeIntegration电源,但是我已经启用了它。
这是我的main.js:
const electron = require('electron');
const {app, BrowserWindow} = electron;
let win;
app.on('ready', () => {
var { width, height } = electron.screen.getPrimaryDisplay().workAreaSize;
width = 1600;
height = 900;
win = new BrowserWindow({'minHeight': 850, 'minWidth': 1600, width, height, webPreferences: {
contextIsolation: true,
webSecurity: true,
nodeIntegration: true
}});
win.setMenu(null);
win.loadFile('index.html');
win.webContents.openDevTools()
});
Run Code Online (Sandbox Code Playgroud)
我的index.js(<script src="index.js"></script>目前仅链接到index.html中)require("fs");已注释掉所有其他内容。
我不知道为什么即使nodeIntegration启用了需求仍然无法正常工作。