最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Electron.jsParcel错误:fs.existsSync不是函数

网站源码admin12浏览0评论

Electron.js / Parcel错误:fs.existsSync不是函数

Electron.js / Parcel错误:fs.existsSync不是函数

我正在使用开箱即用的电子/包裹样板electron-react-parcel-boilerplate

但是,当使用electron-react-parcel-boilerplate软件包时,在电子JS控制台中出现以下错误:

redux-beacon-electron

以及我们运行redux-beacon-electron的终端:

Uncaught TypeError: fs.existsSync is not a function
    at getElectronPath (index.js:7)
    at Object.parcelRequire.node_modules/electron/index.js.fs (index.js:18)
    at newRequire (src.a2b27638.js:47)
    at localRequire (src.a2b27638.js:53)
    at Object.parcelRequire.node_modules/electron-ga/lib/side-effects.js.electron (side-effects.ts:1)
    at newRequire (src.a2b27638.js:47)
    at localRequire (src.a2b27638.js:53)
    at Object.parcelRequire.node_modules/electron-ga/lib/helpers.js.qs (helpers.ts:4)
    at newRequire (src.a2b27638.js:47)
    at localRequire (src.a2b27638.js:53)

yarn start

我的直觉是,使用[0] ⚠️ /Users/nyxynyx/electron-app/node_modules/electron/index.js:8:41: Cannot statically evaluate fs argument [0] 6 | function getElectronPath () { [0] 7 | if (fs.existsSync(pathFile)) { [0] > 8 | var executablePath = fs.readFileSync(pathFile, 'utf-8') [0] | ^ [0] 9 | if (process.env.ELECTRON_OVERRIDE_DIST_PATH) { [0] 10 | return path.join(process.env.ELECTRON_OVERRIDE_DIST_PATH, executablePath) [0] 11 | } 启动Parcel时,其包裹没有正确地对准Electron,因此我尝试进行更改

yarn start

"react-start": "parcel -p 3000 index.html --out-dir build",

但是现在Electron应用程序甚至在运行"react-start": "parcel -p 3000 index.html --out-dir build --target node", 时也无法启动,并且在运行"react-start": "parcel -p 3000 index.html --out-dir build --target electron", yarn start之后尝试加载http://localhost:3000时什么也没有显示。

为什么不起作用,有可能解决此错误?

谢谢!


GitHub Repo

yarn start


使用中

  • [email protected]
  • [email protected]
  • [email protected]
  • [email protected]
  • [email protected]
  • 电子@ 8.2.3
  • 包裹打包机@ 1.12.4

packages.json

yarn react-start

如@tpikachu所建议,尝试设置为{ "name": "electron-react-parcel", "version": "1.0.0", "description": "Electron app build using ReactJS and Parcel web application bundler", "main": "src/electron.js", "scripts": { "react-start": "parcel -p 3000 index.html --out-dir build", "react-build": "parcel build index.html --out-dir build --public-url ./", "electron-build": "electron-builder -mwl", "clean-build": "rm -rf build/ .cache dist/", "build": "yarn clean-build && yarn react-build && yarn electron-build", "start": "concurrently \"cross-env BROWSER=none yarn react-start\" \"wait-on http://localhost:3000 && electron . \"", ... ,但仍然存在相同的错误...

electron.js(通常命名为nodeIntegration: true

true
回答如下:

由于软件包版本冲突。如main.js

即使我们使用[email protected]来解决封装冲突也将不稳定,也不适合最新的电子版本。

我们可以使用function createWindow() { const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize; mainWindow = new BrowserWindow({ width: Math.round(width * 0.9), height: Math.round(height * 0.9), webPreferences: { nodeIntegration: true, } }); mainWindow.loadURL( isDev ? "http://localhost:3000" : `file://${path.join(__dirname, "../build/index.html")}` ); mainWindow.on("closed", () => (mainWindow = null)); } app.on("ready", async () => { createWindow(); ... }); 而不是[email protected] has electron@^1.8.2

发布评论

评论列表(0)

  1. 暂无评论