๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Frontend/JavaScript

[ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(JavaScript) ] npm install ํ›„ package-lock.json์˜ diff๊ฐ€ ๋งŽ๊ณ  npm run dev๊ฐ€ ์•ˆ๋  ๋•Œ

by YWTechIT 2022. 6. 13.
728x90

๐Ÿ“npm install ํ›„ package-lock.json์˜ diff๊ฐ€ ๋งŽ๊ณ  npm run dev๊ฐ€ ์•ˆ๋  ๋•Œ

๋‚ด๊ฐ€ ๋‹ด๋‹นํ•œ repository๋ฅผ ๋ณธ๊ฒฉ์ ์œผ๋กœ ์ž‘์—…ํ•˜๊ธฐ ์ „์—, ํ„ฐ๋ฏธ๋„์— npm install์œผ๋กœ ํ•ด๋‹น project๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•˜๋Š” ๋„์ค‘ VSCode์˜ Source Control - Changes์—์„œ main ๋ธŒ๋žœ์น˜์˜ package-lock.json์˜ ์ฝ”๋“œ์™€ ๋‹ค๋ฅด๊ฒŒ diff๊ฐ€ ์—„์ฒญ ๋งŽ์ด ์ƒ๊ธฐ๋ฉด์„œ npm run dev๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋œจ๋ฉด์„œ ์ •์ƒ์ ์œผ๋กœ local ํ™˜๊ฒฝ ์‹คํ–‰์ด ์•ˆ ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์—ˆ๋‹ค.

 

 

main ๋ธŒ๋žœ์น˜์˜ package-lock.json๊ณผ ๋‹ค๋ฅธ๊ฒƒ๋„ ์—†๋Š”๋ฐ ๊ฐ‘์ž๊ธฐ diff๊ฐ€ ๋งŽ์ด ์ƒ๊ฒจ์„œ ๋‹นํ™ฉํ–ˆ์ง€๋งŒ, ์นจ์ฐฉ์„ ์œ ์ง€ํ•˜๋ฉฐ ๊ตฌ๊ธ€๋ง์„ ํ•œ ๊ฒฐ๊ณผ ์›์ธ์€ npm์ด ํ•ญ์ƒ package-lock.json์—์„œ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋ ค๊ณ  ์‹œ๋„ํ•˜๋Š” ํŠน์ง• ๋•Œ๋ฌธ์— ์ƒ๊ธด ๋ฌธ์ œ์˜€๋‹ค. ํ”„๋กœ์ ํŠธ ํŒŒ์ผ ์ค‘ package-lock.json์„ ์ž˜ ๋“ค์—ฌ๋‹ค๋ณด๋ฉด 3๋ฒˆ์งธ ์ค„์— lockfileVersion์ด๋ž€ ์ฝ”๋“œ๊ฐ€ ์žˆ๋Š”๋ฐ, ์ด๋Š” document์˜ ์ฒด๊ณ„์ ์ธ ๋ฒ„์ „์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ฝ”๋“œ์ด๋‹ค.

728x90

lockfileVersion์€ npm์˜ ๋ฒ„์ „์— ๋”ฐ๋ผ 1๊ณผ 2๋กœ ๋‚˜๋‰œ๋‹ค. npm v5 ~ npm v6๋Š” 1์ด ์‚ฌ์šฉ๋˜๊ณ , npm v7์ด์ƒ์€ 2๊ฐ€ ์‚ฌ์šฉ๋œ๋‹ค. (์—ฌ๋‹ด์œผ๋กœ lockfileVersion ๋ฒ„์ „ 3๋„ ์žˆ๋Š”๋ฐ, ์ด๋Š” npm v7์ด์ƒ์—์„œ node_modules/.package-lock.json์˜ ์ˆจ๊ฒจ์ง„ ์ž ๊ธˆ ํŒŒ์ผ์— ์‚ฌ์šฉ๋œ๋‹ค. ๋งŒ์•ฝ, ํ˜„์žฌ ํŒจํ‚ค์ง€๊ฐ€ npm v6์— ๋Œ€ํ•œ ์ง€์›์ด ์—†๋‹ค๋ฉด ํ–ฅํ›„ ๋ฒ„์ „์—์„œ ์‚ฌ์šฉ๋  ๊ฐ€๋Šฅ์„ฑ์ด ๋†’๋‹ค.) ๊ฒฐ๋ก ์ ์œผ๋กœ ๋ฌธ์ œ ์›์ธ์€ lockfileVersion์ด 2์—์„œ 1๋กœ ๋‚ฎ์•„์ง€๋ฉด์„œ ์ƒ๊ธด ๋ฌธ์ œ์ธ๋ฐ, ๋‹น์‹œ ๋‚˜์˜ ๋กœ์ปฌ ํ™˜๊ฒฝ์˜ npm version์€ 6.14.7์ด์—ˆ๊ณ , node version์€ 14.8.0์ด์—ˆ๋‹ค. (npm ๋ฒ„์ „์„ ํ™•์ธํ•˜๋ ค๋ฉด npm -v๋ฅผ, node์˜ ๋ฒ„์ „์„ ํ™•์ธํ•˜๋ ค๋ฉด node -v๋ฅผ ์ž…๋ ฅํ•˜์ž.)

 

ํ•˜์ง€๋งŒ, ์ด์ „๊นŒ์ง€ ๋‚˜๋Š” npm์˜ ๋ฒ„์ „์„ ๊ฐ•์ œ๋กœ ๋‚ฎ์ถ˜์ ์ด ์—†์—ˆ์—ˆ๋Š”๋ฐ ์™œ downgrade๊ฐ€ ๋๋Š”์ง€ ๊ณฐ๊ณฐ์ด ์ƒ๊ฐํ•ด๋ณด๋‹ˆ legacy ํ”„๋กœ์ ํŠธ๋ฅผ ์‹คํ–‰์‹œํ‚ฌ ๋•Œ ์ตœ์‹  node version ์ง€์›์ด ์•ˆ๋˜์–ด์„œ nvm์œผ๋กœ node version์„ ๊ฐ•์ œ๋กœ ๋‚ฎ์ถ”์—ˆ๋”๋‹ˆ ํ•ด๋‹น node version์— ํ˜ธํ™˜๋˜๋Š” npm version์œผ๋กœ ๋ฐ”๋€Œ์—ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์ดํ›„ ์‚ฝ์งˆํ•ด๋ณด๋ฉฐ ์•Œ๊ฒŒ ๋œ ์‚ฌ์‹ค์ธ๋ฐ node-version๊ณผ ํ˜ธํ™˜๋˜๋Š” npm ๋ฒ„์ „์ด ์žˆ์—ˆ๋‹ค. (Reference 2๋ฒˆ ์ฐธ๊ณ )

 

์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด nodejs.org์— ์ ‘์†ํ•˜์—ฌ node.js์—์„œ ์ œ๊ณตํ•˜๋Š” ์•ˆ์ •์ ์ธ ๋…ธ๋“œ ๋ฒ„์ „์ธ 16.15.1 LTS๋ฅผ ์„ค์น˜ํ•˜๊ณ , ํ•ด๋‹น ๋…ธ๋“œ๋ฒ„์ „๊ณผ ํ˜ธํ™˜๋˜๋Š” npm ๋ฒ„์ „์ธ 8.11.0์„ ์„ค์น˜ํ•˜๊ณ ๋‚˜์„œ npm install์„ ํ•˜๋‹ˆ๊นŒ package-lock.json์˜ diff๊ฐ€ ์—†์ด ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜์—ˆ๋‹ค.

 

ํ„ฐ๋ฏธ๋„ ๋ช…๋ น์–ด๋Š” nvm ls -remote๋กœ ์ง€์›๋˜๋Š” ๋…ธ๋“œ ๋ฒ„์ „์„ ํ™•์ธํ•˜๊ณ , nvm install 16.15.1๋กœ ํ•ด๋‹น ๋…ธ๋“œ ๋ฒ„์ „์„ nvm์— ์„ค์น˜ํ•˜๊ณ ,(nvm์ด ์—†๋‹ค๋ฉด ์„ค์น˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๊ตฌ๊ธ€์— ์ฐพ์•„๋ณด์ž.) npm use 16.15.1๋กœ ๋…ธ๋“œ ๋ฒ„์ „์„ ์ ์šฉ์‹œํ‚ค๊ณ , ๋งˆ์ง€๋ง‰ npm install -g npm@8.11.0์œผ๋กœ npm์˜ ๋ฒ„์ „์„ ๋งž์ถฐ์ฃผ์—ˆ๋‹ค.

 

์ด๋ ‡๊ฒŒ ๋˜ ํ•˜๋‚˜์˜ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ๋‹ค. ํ˜น์‹œ๋ผ๋„ ๋‚˜์™€ ๊ฐ™์€ ๋ฌธ์ œ๋กœ ๊ณ ์ƒํ•˜๊ณ  ์žˆ๋Š” ๋‹ค๋ฅธ ๋ถ„๋“ค์—๊ฒŒ ๋„์›€์ด ๋˜์—ˆ์œผ๋ฉด ์ข‹๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์„ ํ•˜๋ฉฐ ๊ธ€์„ ๋งˆ์นœ๋‹ค.

 

Reference

  1. https://docs.npmjs.com/cli/v8/configuring-npm/package-lock-json
  2. https://nodejs.org/ko/download/releases/
  3. https://nodejs.org/ko/
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€