在尝试在电子之间进行通信并做出反应时,我遇到了上面提到的错误。
在我的App.js
文件中:这导致了错误。
const { ipcRenderer, remote } = require('electron');
console.log('electron', ipcRenderer);
我有两个电子文件。启动器(主)和预加载。
我已经尝试了几件事。
我在预加载文件中添加了这个,但仍然出现该错误。
window.ipcRenderer = require('electron').ipcRenderer;
在启动器(主)文件中:
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
contextIsolation: false,
preload: path.join(__dirname, '/electron-preload.js'),
},
});
添加错误堆栈:
TypeError: fs.existsSync is not a function
getElectronPath
http://localhost:3000/static/js/2.chunk.js:423053:10
423050 | var pathFile = path.join(__dirname, 'path.txt');
423051 |
423052 | function getElectronPath() {
> 423053 | if (fs.existsSync(pathFile)) {
| ^ 423054 | var executablePath = fs.readFileSync(pathFile, 'utf-8');
423055 |
423056 | if (Object({"NODE_ENV":"development","PUBLIC_URL":"","WDS_SOCKET_HOST":undefined,"WDS_SOCKET_PATH":undefined,"WDS_SOCKET_PORT":undefined,"REACT_APP_BASE_URL":"https://api.staging.fab.delivery/api/v2","REACT_APP_BASE_URL_V3":"https://api.staging.fab.delivery/api/v3","REACT_APP_apiKey":"AIzaSyAmbEZZ5a1YWlvYfeUpOUJZHlkqvRRNA6c","REACT_APP_projectId":"fab-delivery-staging","REACT_APP_messagingSenderId":"354389721186","REACT_APP_appId":"1:354389721186:web:3dd5bde4e7bebc337d513b","REACT_APP_SENTRY_URL":"https://3e076ee5293b41a396ae1a37c18ee399@sentry.levaral.com/37","REACT_APP_SENTRY_ENVIRONNMENT":"staging"}).ELECTRON_OVERRIDE_DIST_PATH) {
View source
(anonymous function)
node_modules/electron/index.js:18
15 | }
16 | }
17 |
> 18 | module.exports = getElectronPath()
19 |