asar: fails with an error "No such file or directory"

when trying to extract all files from an .asar file I’m getting such an error.

asar extract app.asar ./app
fs.js:565
fs.write = function(fd, buffer, offset, length, position, callback) {
                                                 ^
Error: ENOENT, no such file or directory '/Users/maddev/Documents/projects/personal/slack/app.asar.unpacked/node_modules/cld-atom-shell/build/Release/cld.node'
    at Error (native)
    at Object.fs.openSync (fs.js:500:18)
    at Object.fs.readFileSync (fs.js:352:15)
    at Object.module.exports.readFileSync (/opt/local/lib/node_modules/asar/lib/disk.js:121:19)
    at Object.module.exports.extractAll (/opt/local/lib/node_modules/asar/lib/asar.js:115:24)
    at Command.<anonymous> (/opt/local/lib/node_modules/asar/bin/asar:53:15)
    at Command.listener (/opt/local/lib/node_modules/asar/node_modules/commander/index.js:249:8)
    at Command.emit (events.js:110:17)
    at Command.parseArgs (/opt/local/lib/node_modules/asar/node_modules/commander/index.js:480:12)
    at Command.parse (/opt/local/lib/node_modules/asar/node_modules/commander/index.js:372:21)

what is the problem here? thx

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 16 (4 by maintainers)

Most upvoted comments

This issue is pretty straight forward. Basically lots of apps have an app.asar file but they also have an app.asar.unpacked folder for some files that shouldn’t live in an ASAR. This means that an ASAR file will not extract correctly unless both the app.asar.unpacked and app.asar files are in the same location.

And if you don’t have the app.asar.unpacked folder WITH the ~original files, then the extract process fails and halts, and you can’t easily extract the rest of the files. The above source code hack works, but then probably prevents extract working for files that were listed but not actually packed (for people that want that). It would be nice if asar extract had an additional option to ignore asar.unpacked errors, maybe even by default, or at least some help text specifying on that error, that you can specify this extra option to fully extract all the actually packed files.

I just ran into this problem myself… I believe it is because the asar has excluded directories from the .asar package and to successfully unpack it you need to have the ‘app.asar.unpacked’ directory adjacent to the .asar file while extracting.

went into asar/lib/disk.js, inside the method readFileSync(…), and changed the following: if (info.unpacked) { // it’s an unpacked file, copy it. buffer = fs.readFileSync(path.join(${filesystem.src}.unpacked, filename)) } else { … }

to

if (info.unpacked) { // it’s an unpacked file, copy it. //buffer = fs.readFileSync(path.join(${filesystem.src}.unpacked, filename)) } else { … }

A possible workaround is to use absolute paths for the archive argument. eg asar.extractAll(__dirname + 'src.asar', 'dest')

That error seems expected, we can’t just invent or make the files out of nowhere, the manifest says they’re there, they actually aren’t, so we throw an error for each one. After the change I linked above every other file is still extracted but we will always log / throw the error for the missing ones

Closing out as https://github.com/electron/asar/issues/37#issuecomment-298966504 is the underlying issue folks are experiencing