You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron.js与Next.js构建时持续报错,常规修复无效

Electron + Next.js 构建报错:TypeError: Class extends value # is not a constructor or null

在使用 Electron.js 搭配 Next.js 进行项目构建时,反复触发以下错误:

C:\Users\Himanshu\Desktop\claros\node_modules\minizlib\index.js:192
  [_superWrite] (data) {
   ^
TypeError: Class extends value #<Object> is not a constructor or null
    at Object.<anonymous> (C:\Users\Himanshu\Desktop\claros\node_modules\minizlib\index.js:192:4)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (C:\Users\Himanshu\Desktop\claros\node_modules\app-builder-lib\node_modules\tar\lib\pack.js:26:14)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (C:\Users\Himanshu\Desktop\claros\node_modules\app-builder-lib\node_modules\tar\lib\create.js:6:14)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

已尝试的操作:

  • 更新所有依赖版本
  • 删除并重装 node_modules 目录
  • 切换不同的 Node.js 版本

解决方案

1. 强制锁定 minizlib 兼容版本

该错误通常是由于minizlib版本与当前 Node.js 环境不兼容导致的,可通过强制指定版本解决:

  • Yarn 用户:在package.json中添加resolutions字段:
"resolutions": {
  "minizlib": "2.1.2"
}

执行yarn install重新安装依赖。

  • NPM 用户:在package.json中添加overrides字段:
"overrides": {
  "minizlib": "2.1.2"
}

执行npm install重新安装依赖。

2. 彻底清理缓存后重构

执行以下命令清除所有缓存和旧依赖,再重新构建:

# Yarn 命令
yarn cache clean
rm -rf node_modules yarn.lock
yarn install
yarn build

# NPM 命令
npm cache clean --force
rm -rf node_modules package-lock.json
npm install
npm run build

3. 调整 electron-builder 版本

错误链涉及app-builder-lib,尝试将electron-builder切换到稳定版本(如24.6.4),修改package.json后重新安装依赖:

"devDependencies": {
  "electron-builder": "24.6.4"
}

内容的提问来源于stack exchange,提问作者Himanshu Yadav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 23:43:41