diff --git a/content/posts/2019/使用Electron+React开发跨平台桌面应用.md b/content/posts/2019/使用Electron+React开发跨平台桌面应用.md index a2c4f15..402f5d0 100644 --- a/content/posts/2019/使用Electron+React开发跨平台桌面应用.md +++ b/content/posts/2019/使用Electron+React开发跨平台桌面应用.md @@ -53,7 +53,7 @@ const isDev = require('electron-is-dev'); let mainWindow; function createWindow() { - mainWindow = new BrowserWindow({width: 900, height: 680}); + mainWindow = new BrowserWindow({width: 900, height: 680, webPreferences: {nodeIntegration: true}}); mainWindow.loadURL(isDev ? 'http://localhost:3000' : `file://${path.join(__dirname, '../build/index.html')}`); if (isDev) { // Open the DevTools. @@ -399,7 +399,19 @@ F:\Project\electron\web-designer-test ``` +## 开发笔记 +### 填坑记录 + +- 启动报错`'require()' is not defined.` + + 从Electron 5.0版本开始,`nodeIntegration`默认值由`true`改为`false`,具体可以参考[官方文档](https://github.com/electron/electron/blob/master/docs/api/breaking-changes.md#planned-breaking-api-changes-50),修改方式是在创建窗口时指定值为`true`即可。 + + ```javascript + mainWindow = new BrowserWindow({width: 900, height: 680, webPreferences: {nodeIntegration: true}}); + ``` + + *参考文档*