samuelmeuli / action-electron-builder

:electron: GitHub Action for building and releasing Electron apps
MIT License
658 stars 201 forks source link

TypeError: Cannot read property 'getType' of undefined #63

Closed ransome1 closed 1 year ago

ransome1 commented 3 years ago

Hi @samuelmeuli ,

just since recently I'm running in issues with this action. The building is running through well, but as soon as the publishing to a tag starts, the process stops and runs into a TypeError: Cannot read property 'getType' of undefined which is part of electron-publish, which again is part of electron-builder. I'm using 22.10.5. Have you even stumbled accross this TypeError and can point me into the right direction how to solve it?

In case it matters, here is my package.json (https://github.com/ransome1/sleek/blob/develop/package.json) and here the full build log (https://github.com/ransome1/sleek/runs/2506836432?check_suite_focus=true)

I would really appreciate any help, as I can't publish my builds right now :(

yarn run v1.22.10
$ /home/runner/work/sleek/sleek/node_modules/.bin/electron-builder --linux --publish always
  • electron-builder  version=22.10.5 os=5.4.0-1046-azure
  • cannot check updates  error=TypeError: update_notifier_1.default is not a function
  • loaded configuration  file=package.json ("build" field)
  • packaging       platform=linux arch=x64 electron=12.0.6 appOutDir=dist/linux-unpacked
  • building        target=AppImage arch=x64 file=dist/sleek-1.0.3.AppImage
  • publishing      publisher=Github (owner: ransome1, project: sleek, version: 1.0.3)
  • building        target=deb arch=x64 file=dist/sleek_1.0.3_amd64.deb
  • uploading       file=sleek-1.0.3.AppImage provider=GitHub
  • building        target=freebsd arch=x64 file=dist/sleek-1.0.3.freebsd
  • uploading       file=sleek_1.0.3_amd64.deb provider=GitHub
  • building        target=rpm arch=x64 file=dist/sleek-1.0.3.x86_64.rpm
  • uploading       file=sleek-1.0.3.freebsd provider=GitHub
  • uploading       file=sleek-1.0.3.x86_64.rpm provider=GitHub
  ⨯ Cannot cleanup: 

Error #1 --------------------------------------------------------------------------------
TypeError: Cannot read property 'getType' of undefined
    at GitHubPublisher.doUploadFile (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:190:36)
    at GitHubPublisher.doUpload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:170:23)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at GitHubPublisher.upload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/publisher.ts:87:5)

Error #2 --------------------------------------------------------------------------------
TypeError: Cannot read property 'getType' of undefined
    at GitHubPublisher.doUploadFile (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:190:36)
    at GitHubPublisher.doUpload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:170:23)
    at GitHubPublisher.upload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/publisher.ts:87:5)

Error #3 --------------------------------------------------------------------------------
TypeError: Cannot read property 'getType' of undefined
    at GitHubPublisher.doUploadFile (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:190:36)
    at GitHubPublisher.doUpload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:170:23)
    at GitHubPublisher.upload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/publisher.ts:87:5)

Error #4 --------------------------------------------------------------------------------
TypeError: Cannot read property 'getType' of undefined
    at GitHubPublisher.doUploadFile (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:190:36)
    at GitHubPublisher.doUpload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:170:23)
    at GitHubPublisher.upload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/publisher.ts:87:5)  failedTask=build stackTrace=Error: Cannot cleanup: 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Error #1 --------------------------------------------------------------------------------
TypeError: Cannot read property 'getType' of undefined
    at GitHubPublisher.doUploadFile (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:190:36)
    at GitHubPublisher.doUpload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:170:23)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at GitHubPublisher.upload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/publisher.ts:87:5)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Error #2 --------------------------------------------------------------------------------
TypeError: Cannot read property 'getType' of undefined
    at GitHubPublisher.doUploadFile (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:190:36)
    at GitHubPublisher.doUpload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:170:23)
    at GitHubPublisher.upload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/publisher.ts:87:5)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Error #3 --------------------------------------------------------------------------------
TypeError: Cannot read property 'getType' of undefined
    at GitHubPublisher.doUploadFile (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:190:36)
    at GitHubPublisher.doUpload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:170:23)
    at GitHubPublisher.upload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/publisher.ts:87:5)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Error #4 --------------------------------------------------------------------------------
TypeError: Cannot read property 'getType' of undefined
    at GitHubPublisher.doUploadFile (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:190:36)
    at GitHubPublisher.doUpload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/gitHubPublisher.ts:170:23)
    at GitHubPublisher.upload (/home/runner/work/sleek/sleek/node_modules/electron-publish/src/publisher.ts:87:5)
    at throwError (/home/runner/work/sleek/sleek/node_modules/builder-util/src/asyncTaskManager.ts:88:11)
    at checkErrors (/home/runner/work/sleek/sleek/node_modules/builder-util/src/asyncTaskManager.ts:53:9)
    at AsyncTaskManager.awaitTasks (/home/runner/work/sleek/sleek/node_modules/builder-util/src/asyncTaskManager.ts:58:5)
    at PublishManager.awaitTasks (/home/runner/work/sleek/sleek/node_modules/app-builder-lib/src/publish/PublishManager.ts:228:28)
    at /home/runner/work/sleek/sleek/node_modules/app-builder-lib/src/index.ts:114:32
    at Object.executeFinally (/home/runner/work/sleek/sleek/node_modules/builder-util/src/promise.ts:23:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
/home/runner/work/_actions/samuelmeuli/action-electron-builder/v1/index.js:144
                throw err;
                ^

Error: Command failed: yarn run electron-builder --linux --publish always 
    at checkExecSyncError (child_process.js:621:11)
    at execSync (child_process.js:657:15)
    at run (/home/runner/work/_actions/samuelmeuli/action-electron-builder/v1/index.js:21:27)
    at runAction (/home/runner/work/_actions/samuelmeuli/action-electron-builder/v1/index.js:132:4)
    at Object.<anonymous> (/home/runner/work/_actions/samuelmeuli/action-electron-builder/v1/index.js:150:1)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 2369,
  stdout: null,
  stderr: null
}
ransome1 commented 3 years ago

The problem seems to be, that gitHubPublisher.ts tries to read the mime type of the file, which has been build before, but cannot access it, or at least for some reason it is not defined.

Line 190: "Content-Type": mime.getType(fileName) || "application/octet-stream",

The issue happens in this function in the electron-builder module:

  private doUploadFile(
    attemptNumber: number,
    parsedUrl: UrlWithStringQuery,
    fileName: string,
    dataLength: number,
    requestProcessor: (request: ClientRequest, reject: (error: Error) => void) => void,
    release: any
  ): Promise<any> {
    return httpExecutor
      .doApiRequest(
        configureRequestOptions(
          {
            hostname: parsedUrl.hostname,
            path: parsedUrl.path,
            method: "POST",
            headers: {
              accept: "application/vnd.github.v3+json",
              "Content-Type": mime.getType(fileName) || "application/octet-stream",
              "Content-Length": dataLength,
            },
          },
          this.token
        ),
        this.context.cancellationToken,
        requestProcessor
      )
      .catch(e => {
        if (e.statusCode === 422 && e.description != null && e.description.errors != null && e.description.errors[0].code === "already_exists") {
          return this.overwriteArtifact(fileName, release).then(() => this.doUploadFile(attemptNumber, parsedUrl, fileName, dataLength, requestProcessor, release))
        }

        if (attemptNumber > 3) {
          return Promise.reject(e)
        } else {
          return new Promise((resolve, reject) => {
            const newAttemptNumber = attemptNumber + 1
            setTimeout(() => {
              this.doUploadFile(newAttemptNumber, parsedUrl, fileName, dataLength, requestProcessor, release).then(resolve).catch(reject)
            }, newAttemptNumber * 2000)
          })
        }
      })
  }

https://github.com/electron-userland/electron-builder/blob/9305fefa1265ec1a244b0003bd4489731d5f15a4/packages/electron-publish/src/gitHubPublisher.ts#L190

ransome1 commented 3 years ago

To whom it may concern, the issue is also discussed on electron builder directly: https://github.com/electron-userland/electron-builder/issues/5861