electron-builder icon indicating copy to clipboard operation
electron-builder copied to clipboard

Some files are flagged as `unpack: true` in asar

Open rajzik opened this issue 4 months ago • 8 comments

I am trying to package my app for mac universal and the build fails on unpacking due to misconfigured flag unpack: true for the files.

Configuration
{
    "$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/refs/heads/master/packages/app-builder-lib/scheme.json",
    "framework": "electron",
    "asar": true,
    "productName": "...",
    "files": ["out/**/*", "renderer/out/**/*", "!**/node_modules/{esbuild,@esbuild}/**/*"],
    "afterSign": "./scripts/macos-notarize.cjs",
    "afterPack": "./scripts/after-pack.cjs",
    "afterAllArtifactBuild": "./scripts/after-all-artifact-build.cjs",
    "mac": {
        "extraFiles": ["./PrivacyInfo.xcprivacy"],
        "target": ["dmg"],
        "icon": "./renderer/out/branding/images/icon-1240x1240.png",
        "category": "public.app-category.utilities",
        "artifactName": "${productName}-${os}-${arch}-${version}.${ext}",
        "electronLanguages": ["de", "de_DE"],
        "mergeASARs": true,
        "singleArchFiles": "...",
        "extendInfo": {
            "ITSAppUsesNonExemptEncryption": false
        },
        "x64ArchFiles": "..."
    },
    "mas": {
        "type": "distribution",
        "provisioningProfile": ".match/...",
        "hardenedRuntime": false,
        "entitlements": "variants/entitlements.mas.plist",
        "entitlementsInherit": "variants/entitlements.mas.inherit.plist",
        "entitlementsLoginHelper": "variants/entitlements.mas.loginhelper.plist"
    },
    "pkg": {
        "scripts": "../../build/pkg-scripts",
        "installLocation": "/Applications",
        "allowAnywhere": true,
        "allowCurrentUserHome": true,
        "allowRootDirectory": true,
        "isVersionChecked": false,
        "isRelocatable": false,
        "overwriteAction": "upgrade"
    },
    "win": {
        "target": ["appx", "nsis"],
        "icon": "./renderer/out/branding/images/icon-1024x1024.png",
        "artifactName": "${productName}-${os}-${arch}-${version}.${ext}"
    },
    "linux": {
        "target": "AppImage",
        "artifactName": "${productName}-${os}-${arch}-${version}.${ext}",
        "icon": "./renderer/out/branding/images/icon-1024x1024.png"
    },
    "nsis": {
        "perMachine": true
    },
    "directories": {
        "buildResources": "renderer/out/"
    },
    "extraMetadata": {
        "productName": "ePA"
    },
    "asarUnpack": ["**/*.xsd"]
}
Depedencies
{
    "@electron/fuses": "2.0.0",
    "@electron/notarize": "3.0.1",
    "electron": "37.2.4",
    "electron-builder": "26.0.19",
    "electron-better-ipc": "2.0.1",
    "electron-devtools-installer": "4.0.0",
    "electron-log": "5.4.2",
    "electron-store": "10.1.0",
}

Build command

DEBUG=electron-builder electron-builder --config "./variants/default.config.json" --mac --universal

Output

Relevant Output
  • packaging       platform=darwin arch=universal electron=37.2.4 appOutDir=dist/mac-universal
  ⨯ ENOENT: no such file or directory, open '/var/folders/p0/mhwqr3n93zb3q_7rkz_0dp740000gn/T/electron-universal-HWw6YC/Tmp.app/Contents/Resources/app.asar.unpacked/out/.main/somexml.xml'  failedTask=build stackTrace=Error: ENOENT: no such file or directory, open '/var/folders/p0/mhwqr3n93zb3q_7rkz_0dp740000gn/T/electron-universal-HWw6YC/Tmp.app/Contents/Resources/app.asar.unpacked/out/.main/some.xml'
    at Object.openSync (node:fs:562:18)
    at Object.readFileSync (node:fs:446:35)
    at Object.readFileSync (/Users/.../git/work/.../node_modules/@electron/asar/src/disk.ts:198:17)
    at Object.extractFile (/Users/.../git/work/.../node_modules/@electron/asar/src/asar.ts:346:15)
    at mergeASARs (/Users/.../git/work/.../node_modules/@electron/universal/src/asar-utils.ts:148:29)
    at makeUniversalApp (/Users/.../git/work/.../node_modules/@electron/universal/src/index.ts:275:23)
    at MacPackager.doPack (/Users/.../git/work/.../node_modules/app-builder-lib/src/macPackager.ts:156:9)
    at MacPackager.pack (/Users/.../git/work/.../node_modules/app-builder-lib/src/macPackager.ts:220:9)
    at Packager.doBuild (/Users/.../git/work/.../node_modules/app-builder-lib/src/packager.ts:507:11)
    at executeFinally (/Users/.../git/work/.../node_modules/builder-util/src/promise.ts:12:14)

After some digging I found out that files that throws ENOENT error are flagged by unpack: true during the unpack and hence not found. For some reason xml, pem, cjs extensions are flagged as upacked even when they are not.

rajzik avatar Aug 06 '25 16:08 rajzik

First off, thank you so much for a detailed issue report!

Looks like this error is coming from @electron/asar, but the unpack detection logic is indeed in electron-builder that is calling makeUniversalApp of @electron/universal

Would you be willing to put together a minimum repro repo for this so that I can quickly debug? I may need to fix a bug upstream if I can identify what's going wrong.

mmaietta avatar Aug 07 '25 17:08 mmaietta

@mmaietta minimal repro: https://github.com/rajzik/electron-builder-repro

rajzik avatar Aug 11 '25 10:08 rajzik

@mmaietta any update?

rajzik avatar Aug 22 '25 09:08 rajzik

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment, or this will be closed in 30 days.

github-actions[bot] avatar Sep 22 '25 00:09 github-actions[bot]

Can we keep this alive?

rajzik avatar Sep 27 '25 22:09 rajzik

@rajzik are you still able to reproduce this on v26.3.0?

mmaietta avatar Nov 21 '25 02:11 mmaietta

@mmaietta still the same error.

ENOENT: no such file or directory, open '/var/folders/p0/mhwqr3n93zb3q_7rkz_0dp740000gn/T/electron-universal-B7tUgw/Tmp.app/Contents/Resources/app.asar.unpacked/main/assets/b/b.xml'  failedTask=build stackTrace=Error: ENOENT: no such file or directory, open '/var/folders/p0/mhwqr3n93zb3q_7rkz_0dp740000gn/T/electron-universal-B7tUgw/Tmp.app/Contents/Resources/app.asar.unpacked/main/assets/b/b.xml'

rajzik avatar Dec 01 '25 13:12 rajzik

@mmaietta Update repro repo.

rajzik avatar Dec 01 '25 13:12 rajzik

@mmaietta Any update on this one? Same issue on our end.

eitambelahousky avatar Dec 15 '25 05:12 eitambelahousky

Well, I've verified my PR fixes the packaging issue, but I'm just struggling to figure out how to verify the change causes no issues with .framework file/folder/symlink structure during app runtime.

mmaietta avatar Dec 15 '25 15:12 mmaietta