ReferenceError: BigInt is not defined Asar Electron Nodejs

10.8k views Asked by At

Hello have been trying to extract and repack an app.asar to update files inside the package :

await asar.extractAll(path.join(__dirname, './app.asar'),path.join(__dirname, './destfolder'));

Then changing some files in destfolder then

await asar.createPackage(path.join(__dirname, './destfolder'),path.join(__dirname, './app.asar'));

But i have been getting this error :

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)

Platform : Windows x64 Node version : v14.15.1

I don't know if this is a bug, but i have been stuck on this for about 2 days now and didn't find a solution I created an issue here : https://github.com/electron/asar/issues/217 Thank you for your efforts, dont hestitate to ask for any information

UPDATE

In the node module asar folder package.json :

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

I tried changing it to :

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

Still i didn't work

LAST UPDATE RESOLVED

Electron runs it's own version of nodejs and i hadn't the last package version. Once i updated my electron package, everything worked ! Hope that this will help someone

2

There are 2 answers

0
jfriend00 On BEST ANSWER

That error is apparently coming from this line of code in the asar package's lib/filesystem.js:

this.offset = BigInt(0)

And, the error apparently means that you have a version of nodejs that electron is using when it builds your app that does not support BigInt which was added in v10.4.

So, though you think you are using v14.15.1, that is apparently not what electron is building your app with. You need to upgrade the version of nodejs you're using in this electron project.

You can confirm what version of nodejs is being used by adding this to some of your own code in the project:

console.log(process.version);
0
Tim Long On

If you manage your node version using nvm, please check if node -v and nvm alias default returns the same node version.

Tools like jenkins, forever... which start nodejs application, will use the default version of node, which could be different than the version used by terminal console.

Do the check: nvm list

Fix the difference: nvm alias default "node -v"