컴퓨터 공학/JavaScript

pkg 모듈 실행 시 "(0, assert_1.default)(!this.bar)" 에러 발생하는 경우

혼새미로 2022. 12. 4. 10:45
반응형

Patrick Star drawn by Zdzisław Beksiński

발생문제

Node.js를 v14에서 v16으로 버전업 후 pkg 모듈을 통해 실행파일을 생성하려고 하면 아래와 같은 에러가 발생할 수 있습니다.

> pkg@5.7.0
> Fetching base Node.js binaries to PKG_CACHE_PATH
  fetched-v16.15.0-win-x64            [                    ] 0%> Not found in remote cache:
  {"tag":"v3.4","name":"node-v16.15.0-win-x64"}
> Building base binary from source:
  built-v16.15.0-win-x64
> Fetching Node.js source archive from nodejs.org...
> Error! AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  (0, assert_1.default)(!this.bar)

    at Log.enableProgress (D:\projects\proto-downloader_alice\node_modules\pkg-fetch\lib-es5\log.js:64:30)
    at D:\projects\proto-downloader_alice\node_modules\pkg-fetch\lib-es5\utils.js:58:31
    at step (D:\projects\proto-downloader_alice\node_modules\pkg-fetch\lib-es5\utils.js:33:23)
    at Object.next (D:\projects\proto-downloader_alice\node_modules\pkg-fetch\lib-es5\utils.js:14:53)
    at D:\projects\proto-downloader_alice\node_modules\pkg-fetch\lib-es5\utils.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (D:\projects\proto-downloader_alice\node_modules\pkg-fetch\lib-es5\utils.js:4:12)
    at downloadUrl (D:\projects\proto-downloader_alice\node_modules\pkg-fetch\lib-es5\utils.js:53:12)
    at D:\projects\proto-downloader_alice\node_modules\pkg-fetch\lib-es5\build.js:142:66
    at step (D:\projects\proto-downloader_alice\node_modules\pkg-fetch\lib-es5\build.js:44:23)

문제해결

Step 1. pkg-fetch 다운로드

에러 메시지에서 발생한 버전에 맞는 pkg-fetch를 다운로드 받아야 합니다.

https://github.com/vercel/pkg-fetch/releases

 

Releases · vercel/pkg-fetch

A utility to fetch or build patched Node binaries used by `pkg` to generate executables. This repo hosts prebuilt binaries in Releases. - vercel/pkg-fetch

github.com

위 에러 메시지에 의하면 node-v16.15.0-win-x64를 찾을 수 없었기 때문에 해당 파일을 다운로드 받습니다.

Asserts를 클릭합니다.

일치하는 버전의 파일을 선택하여 다운로드 받습니다.

Step 2. pkg-fetch 파일 이동

C:\Users\${사용자이름}\.pkg-cache 경로에 보면 다음과 같이 pkg 버전들이 여러 개 존재할 수 있습니다.

에러 메시지에서는 {"tag": "v3.4"} 를 다루고 있으므로, v3.4 폴더에 다운로드 받은 파일을 이동시킵니다.

그리고 파일 이름을 node-v16.15.0-win-x64에서 fetched-v16.15.0-win-x64로 변경합니다.

Step 3. pkg 모듈 작동 확인

이제 다시 돌아와서 pkg 모듈을 사용하여 실행파일이 정상적으로 생성되는지 확인합니다.

반응형