본문 바로가기
카테고리 없음

[CI/CD] Vite 프로젝트 배포 시 crypto.getRandomValues 에러 해결

by soro.k 2025. 2. 5.

 

 

 

01. 상황

Jenkins에서 Vite 기반의 Vue 프로젝트를 빌드하던 중에 에러가 발생했다.

error during build:
TypeError: crypto$2.getRandomValues is not a function
    at resolveConfig (file:///var/jenkins_home/workspace/{프로젝트이름}/node_modules/vite/dist/node/chunks/dep-CHZK6zbr.js:66562:16)
    at async build (file:///var/jenkins_home/workspace/{프로젝트이름}/node_modules/vite/dist/node/chunks/dep-CHZK6zbr.js:65395:18)
    at async CAC.<anonymous> (file:///var/jenkins_home/workspace/{프로젝트이름}/node_modules/vite/dist/node/cli.js:829:5)[39m
Build step 'Execute shell' marked build as failure
SSH: Current build result is [FAILURE], not going to run.
[Slack Notifications] found #68 as previous completed, non-aborted build
[Slack Notifications] will send OnEveryFailureNotification because build matches and user preferences allow it
Finished: FAILURE

 

 

02.원인

찾아보니 Node.js의 crypto 모듈에서 발생한 에러였고 관련 에러에 대해 Vite 레포지토리에 이미 리포트된 이슈들이 있었다. 아래 이슈는 Bitbucket을 통해 빌드를 하던 도중 같은 에러를 겪고 해결 방법을 묻는 내용인데, 그 밑에 달린 답변을 통해 Node 버전이 낮을 때 해당 문제가 발생한다는 사실을 알게 되었다.

 

 

Just suddenly vite is causing some error in bitbucket.. I saw a fix for this but what about 5.4.14? · Issue #19260 · vitejs/v

Describe the bug I am using 5.4.14 and started getting this today . I have not compiled in 2 days .. there was some change 2 days ago that I saw someone do a fix for This is on bitbucket.. . pullin...

github.com

 

 

실제로 Node.js 공식문서를 통해 crypto.getRandomValues()가 Node 17.4.0 버전에 추가된 것을 확인할 수 있다.

출처 : https://nodejs.org/api/crypto.html#cryptogetrandomvaluestypedarray

 

 

 

03. 해결

Jenkins 빌드 환경에서는 Node 버전을 확인하고 업그레이드하면 된다. 이 설정 값은 Configuration > General > Build Steps 영역에서 확인할 수 있다.