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

Electron提取重打包asar包报ReferenceError: BigInt is not defined错误如何解决

Electron项目操作asar包出现ReferenceError: BigInt is not defined的解决方案

问题场景

在Electron项目中需要提取并重新打包app.asar更新包内文件,执行以下操作时报错:

  • 提取asar包代码:await asar.extractAll(path.join(__dirname, './app.asar'),path.join(__dirname, './destfolder'));
  • 修改目录内文件后重新打包代码:await asar.createPackage(path.join(__dirname, './destfolder'),path.join(__dirname, './app.asar'));

完整报错信息

ReferenceError: BigInt is not defined
    at new Filesystem (C:\Users\Path\to\project\node_modules\asar\lib\filesystem.js:17:5)
    at Object.module.exports.readFilesystemSync (C:\Users\Path\to\project\node_modules\asar\lib\disk.js:85:24)
    at Object.module.exports.extractAll (C:\Users\Path\to\project\node_modules\asar\lib\asar.js:170:27)
    at Request._callback (C:\Users\Path\to\project\server.js:221:26)
    at Request.init.self.callback (C:\Users\Path\to\project\node_modules\request\request.js:185:22)
    at Request.emit (events.js:182:13)
    at Request.<anonymous> (C:\Users\Path\to\project\node_modules\request\request.js:1154:10)
    at Request.emit (events.js:182:13)
    at IncomingMessage.<anonymous> (C:\Users\Path\to\project\node_modules\request\request.js:1076:12)
    at Object.onceWrapper (events.js:273:13)
    at IncomingMessage.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1090:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

运行环境

  • Windows x64系统
  • 全局Node版本v14.15.1

已尝试的无效方案

尝试修改asar依赖包下package.json中的standard配置,将原有配置:

"standard": {
"env": {
  "mocha": true
},
"globals": [
  "BigInt"
]}

修改为:

"standard": {
"env": {
  "es2020": true,
"browser": true,
"node": true,
  "mocha": true
},
"globals": {
  "BigInt":true
}}

修改后问题仍然存在。

最终解决方案

Electron自带独立的Node.js运行环境,该报错是由于使用的Electron包版本过低,内置的Node运行时不支持BigInt导致的,更新Electron包到支持BigInt的版本即可解决问题。


内容的提问来源于stack exchange,提问作者Papou SC

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.21 09:45:05