asar icon indicating copy to clipboard operation
asar copied to clipboard

Failing with scoped node_modules

Open davej opened this issue 6 years ago • 3 comments

Asar seems to fail with modules that are scoped, e.g.. @scope/project-name.

Getting the following error while asar is iterating over the node_modules/@pnpm/default-fetcher directory:

/Users/dave/code/my-app/app/node_modules/asar/lib/filesystem.js:20
        json = json.files[dir]
                    ^

TypeError: Cannot read property 'files' of undefined
    at Filesystem.searchNodeFromDirectory (/Users/dave/code/my-app/app/node_modules/asar/lib/filesystem.js:20:21)
    at Filesystem.searchNodeFromPath (/Users/dave/code/my-app/app/node_modules/asar/lib/filesystem.js:30:23)
    at Filesystem.insertDirectory (/Users/dave/code/my-app/app/node_modules/asar/lib/filesystem.js:41:23)
    at handleFile (/Users/dave/code/my-app/app/node_modules/asar/lib/asar.js:120:20)
    at next (/Users/dave/code/my-app/app/node_modules/asar/lib/asar.js:160:12)
    at /Users/dave/code/my-app/app/node_modules/asar/lib/asar.js:161:14
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

davej avatar Mar 16 '18 12:03 davej

I am not sure if this is the same issue, but I had a similar error message when trying it with the pattern

'/{electron.js,package.json,dist/**/*,node_modules/electron-log/**/*}'

My workaround after debugging this filesystem.js file was to change my pattern to include the parent dir before the subdir, like this:

'/{electron.js,package.json,dist/**/*,node_modules,node_modules/electron-log/**/*}'

fczuardi avatar Nov 29 '18 21:11 fczuardi

I ran into the error when extracting a file this way:

$ asar ef ~/.cache/Cypress/3.4.1/Cypress/resources/electron.asar /browser/api/web-contents.js

In my case the fix was to strip the leading slash:

$ asar ef ~/.cache/Cypress/3.4.1/Cypress/resources/electron.asar browser/api/web-contents.js

Otherwise the first item in the list is empty.

x-yuri avatar Oct 12 '19 14:10 x-yuri

Quick note: I've been trying to migrate electron-builder to use the official electron/asar package, however, this issue is blocking me from properly packaging the asar with the current builder's flow. I can pack all files and let asar figure out what to unpack, but electron-builder also allows a unpack string[] of regexes that I can't figure out how to handle using this asar package. Files are moved/unpacked to app.asar.unpacked folder, but asar doesn't seem to provide that functionality. Any advice/help would be greatly appreciated

mmaietta avatar Aug 11 '22 18:08 mmaietta

@davej this should be fixed in latest asar release

mmaietta avatar Nov 03 '22 22:11 mmaietta