Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to create dylib symbolic link on Windows #8149

Open
kochizufan opened this issue Mar 22, 2024 · 26 comments
Open

Failed to create dylib symbolic link on Windows #8149

kochizufan opened this issue Mar 22, 2024 · 26 comments

Comments

@kochizufan
Copy link

  • Electron-Builder Version: 24.13.3
  • Node Version: v18.16.1
  • Electron Version: 29.1.5
  • Electron Type (current, beta, nightly): current
  • Target: Both NSIS and portable on Windows (Both results are same)

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
Copy link

Mayconoliveyra commented Mar 28, 2024

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
Copy link

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
Copy link

wszgrcy commented Apr 19, 2024

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
Copy link

bfurtonmw commented Apr 19, 2024

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

@renkei
Copy link

renkei commented Apr 26, 2024

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:

  • You don't need admin rights
  • You can use the latest version of electron-builder
  • You need to do this only once as preparation step, also easy to realize in a CI environment

Con

  • You have to do it as long as this issue is not fixed.

@ianoble
Copy link

ianoble commented May 8, 2024

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
Copy link

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.

liamcottle added a commit to liamcottle/reticulum-meshchat that referenced this issue May 27, 2024
@vijaysharma0757
Copy link

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
Copy link

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

@ckarich
Copy link
Contributor

ckarich commented Aug 13, 2024

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
Copy link

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

@bfurtonmw
Copy link

bfurtonmw commented Aug 19, 2024

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
Copy link

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
Copy link

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 in C:\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
Copy link
Collaborator

mmaietta commented Sep 5, 2024

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

@bfurtonmw
Copy link

bfurtonmw commented Sep 5, 2024

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:

  • A 7zip-bin upgrade now attempts to create symlinks on Windows, which requires administrator privileges. Historically, libraries got around this by using hardlinks, but I guess that's not the case anymore.
  • electron-builder itself is only extracting these symlinks on Windows in the first place because it's trying to extract Mac-specific build assets that make heavy use of symlinks. If electron-builder stopped trying to unzip .app folders or whatever on Windows (there's literally no reason to do this) then the issue would be resolved. (Edit: taking back the assumption that there's no reason to do this. There might be, but it would be nice if winCodeSign only downloaded what it needs based on the electron-builder config.)

@beyondkmp
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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 #8149 (comment) and we can proceed with opening a PR upstream for 7zip-bin. There's coincidentally a vulnerability reported develar/7zip-bin#26 that requires it to be updated anyhow.

@mmaietta
Copy link
Collaborator

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
Copy link
Collaborator

Update: I've gotten the new 7zip binaries in PR develar/7zip-bin#27 tested with app-builder-bin's extract logic develar/app-builder#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
Copy link
Collaborator

Alright, got a draft PR up with the updated 7zip binaries. #8530
Dependency on develar/7zip-bin#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
Copy link

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
Copy link

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

@ej-toita
Copy link

For Windows users who still having this problem:

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

@AnneAlbert
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.