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.62k stars 1.74k forks source link

ERR_ELECTRON_BUILDER_CANNOT_EXECUTE, ERR! code E401 Unable to authenticate, your authentication token seems to be invalid. #7008

Closed Stephen-Lamb closed 7 months ago

Stephen-Lamb commented 2 years ago

Hi, I am trying to build my company's electron application, which uses electron-builder, using an Azure DevOps pipeline. However, when I run our "build-release" task in the pipeline I am getting the following error:

  • loaded configuration  file=D:\a\1\s\electron-config.js
  • installing production dependencies  platform=win32 arch=x64 appDir=D:\a\1\s\dist
  ⨯ C:\hostedtoolcache\windows\node\16.16.0\x64\node.exe process failed ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
Exit code:
1
Error output:
npm WARN config production Use `--omit=dev` instead.
npm ERR! code E401
npm ERR! Unable to authenticate, your authentication token seems to be invalid.
npm ERR! To correct this please trying logging in again with:
npm ERR!     npm login

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\npm\cache\_logs\2022-07-19T15_37_41_662Z-debug-0.log
  failedTask=build stackTrace=Error: C:\hostedtoolcache\windows\node\16.16.0\x64\node.exe process failed ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
Exit code:
1
Error output:
npm WARN config production Use `--omit=dev` instead.
npm ERR! code E401
npm ERR! Unable to authenticate, your authentication token seems to be invalid.
npm ERR! To correct this please trying logging in again with:
npm ERR!     npm login
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   npm ERR! A complete log of this run can be found in:
npm ERR!     C:\npm\cache\_logs\2022-07-19T15_37_41_662Z-debug-0.log
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       at ChildProcess.<anonymous> (D:\a\1\s\node_modules\builder-util\src\util.ts:250:14)
    at Object.onceWrapper (node:events:642:26)
    at ChildProcess.emit (node:events:527:28)
    at ChildProcess.cp.emit (D:\a\1\s\node_modules\cross-spawn\lib\enoent.js:34:29)
    at maybeClose (node:internal/child_process:1092:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
##[error]Cmd.exe exited with code '1'.

The project has an .npmrc file which contains the company's repository for node packages, which requires authentication to access. Earlier in the Azure DevOps pipeline I used the task "npmAuthenticate@0" so that the pipeline uses the correct authentication, but it looks like when electron-builder runs it is ignoring this, so authentication fails leading to the "npm login" error message. Any idea how I can resolve this? Thanks.

For reference, here is the Azure DevOps pipline yml file:

trigger:
- SL_pipeline_deploy

pool:
  vmImage: windows-latest

steps:
# Install Node.js
- task: NodeTool@0
  inputs:
    versionSpec: '16.x'
  displayName: 'Install Node.js'

# Delete the package-lock.json file (otherwise the pipeline can fail with package errors)
- task: DeleteFiles@1
  inputs:
    contents: |
      package-lock.json
  displayName: "Remove package-lock.json"

- task: npmAuthenticate@0
  inputs:
    workingFile: .npmrc
  displayName: 'Npm authenticate'

# Npm install
- script: |
    npm install
  displayName: 'Npm install'

# Build the release (for auto update)
- script: |
    npm run build-release
  displayName: 'Npm build-release'

and here is the scripts section from the project's package.json file which details the scripts the pipeline is running:

  "scripts": {
    "build": "webpack --progress --config webpack.config.ts && node src/scripts/updateSourceRoot.js",
    "build-test": "npm run build && npm run test",
    "start": "cd dist && electron .",
    "update-tp": "npm install -D client-ui-toolkit@latest @types/client-api@latest client-test-design-engine@latest",
    "test": "jest --verbose ./unit_tests/",
    "package-all": "npm run package-osx && npm run package-linux && npm run package-win32 && npm run package-win32-arm64",
    "package-osx": "electron-packager dist/ --platform=darwin --arch=x64 --overwrite --out=bin/ --icon=./src/assets/images/pug.icns",
    "package-linux": "electron-packager dist/ --platform=linux --arch=x64 --overwrite --out=bin/ --icon=./src/assets/images/pug_128x128.ico",
    "package-win32": "electron-packager dist/ --platform=win32 --arch=x64 --overwrite --out=bin/ --icon=./src/assets/images/pug_128x128.ico",
    "package-win32-arm64": "electron-packager dist/ --platform=win32 --arch=arm64 --overwrite --out=bin/ --icon=./src/assets/images/pug_128x128.ico",
    "archive": "node src/scripts/createArchives.js",
    "postinstall": "install-app-deps",
    "pack": "electron-builder --dir --config electron-config.js",
    "dist": "electron-builder --config electron-config.js",
    "publish": "electron-builder --config electron-config.js --publish always",
    "build-release": "webpack --progress --config webpack.config.ts --env=production && node src/scripts/updateSourceRoot.js && electron-builder --config electron-config.js --publish always"
  },
psulek commented 1 year ago

I am experiencing same error @Stephen-Lamb , did you found solution to this?

Stephen-Lamb commented 1 year ago

I did find a workaround. I put "npm Rebuild = false" in my package.json file. This stops electron builder from rebuilding native dependencies before packaging the app (which is where I think it was getting hung up). You can find documentation about this command at https://www.electron.build/configuration/configuration.html

psulek commented 1 year ago

@Stephen-Lamb seems like a possible solution for me too. Btw my findings are interesting too, when i run in terminal electron-builder --config config.json it throws such error but when i run in terminal command npm exec -- electron-builder --config config.json it works . When debugging i found some differences in env param passed into spawn in two mentioned commands.

github-actions[bot] commented 8 months ago

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

github-actions[bot] commented 7 months ago

This issue was closed because it has been stalled for 30 days with no activity.