pkg icon indicating copy to clipboard operation
pkg copied to clipboard

`Cannot generate bytecode` / `pkg fails to run "codesign" utility` (even when codesign is present)

Open ryanblock opened this issue 3 years ago • 5 comments

What version of pkg are you using?

5.5.2

What version of Node.js are you using?

v14.18.2

What operating system are you using?

macOS 12.2.1 (21D62)

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node14-macos-x64

Describe the Bug

Running npx pkg fails with the following error:

> [email protected]
> Fetching base Node.js binaries to PKG_CACHE_PATH
  fetched-v14.18.3-macos-x64          [====================] 100%

/Users/ryan/.pkg-cache/v3.2/fetched-v14.18.3-macos-x64-signed: is already signed
> Error! Cannot generate bytecode
  pkg fails to run "codesign" utility. Due to the mandatory signing
  requirement of macOS, executables must be signed. Please ensure the
  utility is installed and properly configured.

However, codesign is indeed installed and available:

⮑  which codesign
/usr/bin/codesign
⮑  codesign
Usage: codesign -s identity [-fv*] [-o flags] [-r reqs] [-i ident] path ... # sign
       codesign -v [-v*] [-R=<req string>|-R <req file path>] path|[+]pid ... # verify
       codesign -d [options] path ... # display contents
       codesign -h pid ... # display hosting paths

(Related: is the fetched-v14.18.3-macos-x64-signed: is already signed line a red herring?)

Expected Behavior

I expect pkg to successfully run or give me a useful, usable error that I can use to fix the issue.

To Reproduce

Steps to reproduce presented above in the bug description; of course happy to narrow down further if you have any ideas on how I can!

ryanblock avatar Apr 01 '22 01:04 ryanblock

I had the same issue. As a workaround you can go to the source code and add a "-f" flag when they call the codesign utility:

https://github.com/vercel/pkg/blob/b63df87586dfb0a5f56e8698f753846edee4a498/lib/mach-o.ts#L62

I started having this issue when I updated my macos version.

brianunlam avatar Jun 01 '22 12:06 brianunlam

@brianunlam that's a nice workaround, did the trick for me. It's super brittle for obvious reasons, @jesec @leerob any reason not to incorporate this into the codesign call permanently so we can close this issue?

ryanblock avatar Aug 09 '22 03:08 ryanblock

$ sed -e s/--sign/-s/ -i ./node_modules/pkg/lib-es5/mach-o.js did the trick for me, FYI.

ryota-ka avatar Sep 14 '22 07:09 ryota-ka

cc @jesec

robertsLando avatar Sep 14 '22 07:09 robertsLando

@brianunlam that's a nice workaround, did the trick for me. It's super brittle for obvious reasons, @jesec @leerob any reason not to incorporate this into the codesign call permanently so we can close this issue?

Here it's the pr

https://github.com/vercel/pkg/pull/1756

brianunlam avatar Sep 14 '22 11:09 brianunlam

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

github-actions[bot] avatar Dec 14 '22 00:12 github-actions[bot]

The issue isn’t stale. It has PR, even. Auto-closing issues is gross.

ryanblock avatar Dec 14 '22 01:12 ryanblock

@ryanblock The PR #1756 is merged. You can close this Issue

134130 avatar Mar 07 '23 14:03 134130

@134130 happy to close this as soon as the fix is released to production. (Maintainers ofc can also close it should they see fit!)

ryanblock avatar Mar 07 '23 16:03 ryanblock

It should be out, yay!

ryanblock avatar Mar 11 '23 23:03 ryanblock