electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.72k stars 1.74k forks source link

Failed to create dylib symbolic link on Windows #8149

Open kochizufan opened 8 months ago

kochizufan commented 8 months ago

I tried to make Windows installer of my app with following command and settings:

electron-builder --win --x64 --config ./build_win.js

build_win.js

const config = {
  "appId": "jp.maplat.editor",
  "directories": {
    "output": "dist"
  },
  "files": [
    "assets/win",
    "backend",
    "css",
    "frontend/api",
    "frontend/dist",
    "frontend/fonts",
    "html",
    "img",
    "locales",
    "package.json",
    "package-lock.json",
    "tms_list.json"
  ],
  "win": {
    "icon": "assets/win/icon_win.ico",
    "target": "portable"
  },
  "nsis":{
    "oneClick": false,
    "allowToChangeInstallationDirectory": true
  }
};

module.exports = config;

But it is failed with following errors:

  • downloading     url=https://github.com/electron-userland/electron-builder-binaries/releases/download/winCodeSign-2.6.0/winCodeSign-2.6.0.7z size=5.6 MB parts=1
  • downloaded      url=https://github.com/electron-userland/electron-builder-binaries/releases/download/winCodeSign-2.6.0/winCodeSign-2.6.0.7z duration=1.104s
  ⨯ cannot execute  cause=exit status 2
                    out=
    7-Zip (a) 21.07 (x64) : Copyright (c) 1999-2021 Igor Pavlov : 2021-12-26

    Scanning the drive for archives:
    1 file, 5635384 bytes (5504 KiB)

    Extracting archive: C:\Users\kochi\AppData\Local\electron-builder\Cache\winCodeSign\618674575.7z
    --
    Path = C:\Users\kochi\AppData\Local\electron-builder\Cache\winCodeSign\618674575.7z
    Type = 7z
    Physical Size = 5635384
    Headers Size = 1492
    Method = LZMA2:24m LZMA:20 BCJ2
    Solid = +
    Blocks = 2

    Sub items Errors: 2

    Archives with Errors: 1

    Sub items Errors: 2

                    errorOut=ERROR: Cannot create symbolic link : �N���C�A���g�͗v�����ꂽ�������ۗL���Ă��܂����B : C:\Users\kochi\AppData\Local\electron-builder\Cache\winCodeS Sign\618674575\darwin\10.12\lib\libcrypto.dylib
    ERROR: Cannot create symbolic link : �N���C�A���g�͗v�����ꂽ�������ۗL���Ă��܂����B : C:\Users\kochi\AppData\Local\electron-builder\Cache\winCodeSign\618674575\darwin\10.1 12\lib\libssl.dylib

                    command='C:\Users\kochi\github\MaplatEditor\node_modules\7zip-bin\win\x64\7za.exe' x -bd 'C:\Users\kochi\AppData\Local\electron-builder\Cache\winCodeSign\618674575.7z' '-oC:\Users\kochi\AppData\Local\electron-builder\Cache\winCodeSign\618674575'
                    workingDir=C:\Users\kochi\AppData\Local\electron-builder\Cache\winCodeSign

Even if I changed the target from NSIS to portable, it was also failed with the same error.

The error says "libssl.dylib" or "Cannot create symbolic link", so I believe it was caused that needless apple resources were extracted in Windows, and failed to create symbolic link on Windows FS. Are there any fix for this or any work-around?

Mayconoliveyra commented 8 months ago

This issue occurs due to a lack of administrator privileges. If you are using an editor like VS Code, run it with administrator privileges.

Alternatively, you can run the command directly in CMD or PowerShell, but make sure to open them as Administrator to avoid permission issues.

Ex: image

bfurtonmw commented 7 months ago

This error is happening in our CI where running as administrator is not allowed. Is there a workaround for running as an unprivileged user?

wszgrcy commented 7 months ago

I also encountered this issue and solved it using 'PowerShell with ADMINISTRATOR' But I didn't see any prompts about building Windows on the official website. Is this the correct operation?

bfurtonmw commented 7 months ago

FYI, it seems like it's an issue with the 7zip upgrade under the hood. Workaround: downgrade to electron-builder@24.6.3.

renkei commented 7 months ago

I've the same issue. There is maybe a better workaround available:

Download the winCodeSign.7z package manually. You can use the same URL as electron-builder is using: https://github.com/electron-userland/electron-builder-binaries/releases/download/winCodeSign-2.6.0/winCodeSign-2.6.0.7z

Then extract the archive to the requested location (I've used 7-Zip 23.01 for Windows) so that you have this folder on your machine: C:\Users\<YourUserName>\AppData\Local\electron-builder\Cache\winCodeSign\winCodeSign-2.6.0\

That's it. I got no errors during extraction. Once the folder exists the download and extraction of the 7z file is skipped during the electron-builder run.

Pro:

Con

ianoble commented 6 months ago

I got 2 errors after extraction:

Cannot create symbolic link : A required privilege is not held by the client. : c:\users[username]\appdata\local\electron-builder\cache\wincodesign\wincodesign-2.6.0\darwin\10.12\lib\libcrypto.dylib Cannot create symbolic link : A required privilege is not held by the client. : c:\users[username]\appdata\local\electron-builder\cache\wincodesign\wincodesign-2.6.0\darwin\10.12\lib\libssl.dylib

ehellman commented 6 months ago

We are experiencing this issue as well, downgrading to electron-builder@24.6.3 helped, for now. Hopefully this can be resolved. The downgrade diff does indeed show that the 7zip dependency has also been downgraded, so I wonder if it would help to pin it to the old version using resolutions, if someone actually needs to be on the latest electron-builder until this is resolved.

vijaysharma0757 commented 6 months ago

This problem is due to privilege. The solution is simple, just open your project folder in CMD or PowerShell with ADMINISTRATOR privileges.

Ex: image

Thanks it worked for me. I have tried many ways done its working fine

matsonkepson commented 4 months ago

also solved by running as Admin privileged user, unfortunately workarounds with fixing the 7z version were not helpful for me...

ckarich commented 3 months ago

the archive just needs to repacked by electron-builder without the links .. so whatever is used to create the archive in the first place includes the option to archive symlinks ... which is not default behaviour of 7z

taylorhadden commented 3 months ago

Also hit this issue. Worked around by running Powershell as admin. Would love to see this fixed properly.

bfurtonmw commented 3 months ago

the archive just needs to repacked by electron-builder without the links .. so whatever is used to create the archive in the first place includes the option to archive symlinks ... which is not default behaviour of 7z

The symlinks are due to the downloader downloading Mac app bundles on Windows. Those symlinks are required for Mac apps to work, but AFAIK there's no reason for the Windows downloader to be downloading Mac build assets. If the downloader only downloaded what it needed, this would not be a problem at all for most users (assuming there's a legitimate reason for this download to be happening in the first place).

mferris77 commented 3 months ago

FYI - I ran into this issue as well. Rather than downgrading, I upgraded to the latest version (25.0.5 currently) as there's a note in the recent changelogs about symlinks, but the issue is still present (windows 11). I followed the instructions above about manually downloading the zipfile and extracting all contents to the electron-builder\cache\winCodeSign folder and it worked perfectly so thanks for that solution, @renkei!

AnshulNigamVWITS commented 2 months ago

I tried using 7zip 23.01 and 24.08, nothing worked.

I downloaded the winCodeSign-2.6.0's source code from https://github.com/electron-userland/electron-builder-binaries/releases/tag/winCodeSign-2.6.0

image

Then navigated to: C:\Users\<Your UserName>\Downloads\electron-builder-binaries-winCodeSign-2.6.0.zip\electron-builder-binaries-winCodeSign-2.6.0\winCodeSign

Copied all the contents and pasted it inC:\Users\<YourUserName>\AppData\Local\electron-builder\Cache\winCodeSign\winCodeSign-2.6.0\

Doing this worked for me! I don't have the administrator access, yet I'm able to get the files from the source code (zip) rather than the 7zip file, so it's working just fine!

Thanks to @renkei for your amazing answer! able to sort this issue out. I guess it's some problem with 7zip itself because I was not able to extract manually too.

mmaietta commented 2 months ago

Hey all, returning to this issue. Am I understanding this correctly? The 7zip file isn't properly able to be extracted or is running into an issue due to the upgrade that occurred in this PR? https://github.com/electron-userland/electron-builder/pull/7829

Wondering if this binary (that created the winCodeSign 7z file) needs to be updated: https://github.com/electron-userland/electron-builder-binaries/blob/master/7za

bfurtonmw commented 2 months ago

Hey all, returning to this issue. Am I understanding this correctly? The 7zip file isn't properly able to be extracted or is running into an issue due to the upgrade that occurred in this PR? #7829

Wondering if this binary (that created the winCodeSign 7z file) needs to be updated: https://github.com/electron-userland/electron-builder-binaries/blob/master/7za

The bug is caused by the confluence of 2 factors:

beyondkmp commented 2 months ago

This should involve releasing winCodeSign for mac/win/linux in electron-builder-binaries based on the system, then downloading the appropriate version for the specific system being used.

Another option is to see if parameters can be added during 7z extraction to convert symbolic links to hard links.

mmaietta commented 2 months ago

Another option is to see if parameters can be added during 7z extraction to convert symbolic links to hard links.

node_modules/7zip-bin/mac/arm64/7za -h  

7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,12 CPUs LE)

Usage: 7za <command> [<switches>...] <archive_name> [<file_names>...]
       [<@listfiles...>]

<Commands>
  a : Add files to archive
  b : Benchmark
  d : Delete files from archive
  e : Extract files from archive (without using directory names)
  h : Calculate hash values for files
  i : Show information about supported formats
  l : List contents of archive
  rn : Rename files in archive
  t : Test integrity of archive
  u : Update files to archive
  x : eXtract files with full paths

<Switches>
  -- : Stop switches parsing
  -ai[r[-|0]]{@listfile|!wildcard} : Include archives
  -ax[r[-|0]]{@listfile|!wildcard} : eXclude archives
  -ao{a|s|t|u} : set Overwrite mode
  -an : disable archive_name field
  -bb[0-3] : set output log level
  -bd : disable progress indicator
  -bs{o|e|p}{0|1|2} : set output stream for output/error/progress line
  -bt : show execution time statistics
  -i[r[-|0]]{@listfile|!wildcard} : Include filenames
  -m{Parameters} : set compression Method
    -mmt[N] : set number of CPU threads
  -o{Directory} : set Output directory
  -p{Password} : set Password
  -r[-|0] : Recurse subdirectories
  -sa{a|e|s} : set Archive name mode
  -scc{UTF-8|WIN|DOS} : set charset for for console input/output
  -scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}} : set charset for list files
  -scrc[CRC32|CRC64|SHA1|SHA256|*] : set hash function for x, e, h commands
  -sdel : delete files after compression
  -seml[.] : send archive by email
  -sfx[{name}] : Create SFX archive
  -si[{name}] : read data from stdin
  -slp : set Large Pages mode
  -slt : show technical information for l (List) command
  -snh : store hard links as links
  -snl : store symbolic links as links
  -sni : store NT security information
  -sns[-] : store NTFS alternate streams
  -so : write data to stdout
  -spd : disable wildcard matching for file names
  -spe : eliminate duplication of root folder for extract command
  -spf : use fully qualified file paths
  -ssc[-] : set sensitive case mode
  -ssw : compress shared files
  -stl : set archive timestamp from the most recently modified file
  -stm{HexMask} : set CPU thread affinity mask (hexadecimal number)
  -stx{Type} : exclude archive type
  -t{Type} : Set type of archive
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName] : Update options
  -v{Size}[b|k|m|g] : Create volumes
  -w[{path}] : assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]{@listfile|!wildcard} : eXclude filenames
  -y : assume Yes on all queries
mmaietta commented 2 months ago

Hmmmm, so there's a manner with which to avoid using 7zip-bin altogether is by using env var USE_SYSTEM_7ZA=true, it seems that can override 7zip-bin https://github.com/develar/7zip-bin/blob/234abf56ddc2935de44e07d5e3c40eecab95d5af/index.js#L5-L8

Might be worth trying that out and test if a newer version of 7za resolves the issue for you?

If it does, then I'd imagine this workaround would no longer be needed https://github.com/electron-userland/electron-builder/issues/8149#issuecomment-2079252400 and we can proceed with opening a PR upstream for 7zip-bin. There's coincidentally a vulnerability reported https://github.com/develar/7zip-bin/issues/26 that requires it to be updated anyhow.

mmaietta commented 2 months ago

FWIW, I've started working on getting 7zip updated. https://github.com/develar/7zip-bin/tree/update-7zip

Few tests are failing for electron-builder with that specific branch, so far I have needed to remove a -mcu switch since it's no longer present with using 7zz. https://github.com/electron-userland/electron-builder/actions/runs/10968249159/job/30459502311

Unfortunately (or fortunately?), 7zz also gets used by the Go dependency app-builder-bin https://github.com/develar/app-builder/blob/master/pkg/util/env.go#L21 This is causing the failures in the electron-builder CI, for both artifact downloading (binDownloadTest) and for .ico conversion (winPackagerTest).

I'll need to investigate further, but it seems we have some package interdependencies and my familiarity with Go is nil.

mmaietta commented 2 months ago

Update: I've gotten the new 7zip binaries in PR https://github.com/develar/7zip-bin/pull/27 tested with app-builder-bin's extract logic https://github.com/develar/app-builder/pull/139

Working on getting the two dependencies running together through electron-builder's CI but running into pnpm install errors trying to pull from a specific pre-release/feature branch

mmaietta commented 2 months ago

Alright, got a draft PR up with the updated 7zip binaries. https://github.com/electron-userland/electron-builder/pull/8530 Dependency on https://github.com/develar/7zip-bin/pull/27

One of the notable changes in app-builder-bin upstream dependency was the need to add the extract flag -snld. It's an undocumented flag but there's probably a reason for that. https://sourceforge.net/p/sevenzip/bugs/2436/ It's needed though to be backward compatible with previous 7zip versions and more notably, it seems previous electron-builder-binaries that were created with the older version of 7zip run into the error linked above

teslasoft-de commented 1 month ago

I could fix this on Windows 10 with this solution by adding my user to the security policy for creating symbolic links: https://superuser.com/questions/124679/how-do-i-create-a-link-in-windows-7-home-premium-as-a-regular-user/125981#125981

Creation of symbolic links requires the SeCreateSymbolicLinkPrivilege (“Create symbolic links”), which is granted only to administrators by default (but you can change that using security policy).

  1. Right click on Start→Run and launch secpol.msc.
  2. Open Security Settings → Local Policies → User Rights Assignment and select Create symbolic links (that represents SeCreateSymbolicLinkPrivilege).
  3. Double-click on the item and add yourself (or the whole Users group) to the list.
mqliutie commented 2 weeks ago

It means i can not use vscode terminal to run package command? because it does not have administrator privilege.Right?

ej-toita commented 1 week ago

For Windows users who still having this problem:

  1. download zip from url below:
  2. unzip it. It won't require any Admin privilege.
  3. copy files and folders under electron-builder-binaries-winCodeSign-2.6.0\winCodeSign into %LOCALAPPDATA%\electron-builder\Cache\winCodeSign\winCodeSign-2.6.0.
  4. electron-builder will start working.
AnneAlbert commented 1 day ago

For what it's worth, I only needed to build with admin rights once, afterwards I can build w/o running vscode as admin