๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“‚ ์•Œ์“ธ ์ง€์‹/์•Œ์•„๋‘๋ฉด ์ข‹์„

์•Œ์•„๋‘๋ฉด ์“ธ๋ฐ์žˆ๋Š” package.json๊ณผ package-lock.json์˜ ์ฐจ์ด

by Dev. Ella 2023. 4. 30.

 

Node.js ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•  ๋•Œ, ํ„ฐ๋ฏธ๋„์— 'npm install'์„ ์ž…๋ ฅํ•˜๋ฉด ์•„๋ž˜ ์‚ฌ์ง„๊ณผ ๊ฐ™์ด ์—ฌ๋Ÿฌ ํŒŒ์ผ๋“ค์ด ๊ธฐ๋ณธ์œผ๋กœ ์„ค์น˜๋œ๋‹ค.

 

ํ”„๋กœ์ ํŠธ ํŒŒ์ผ ๋ชฉ๋ก

 

๊ทธ๋Ÿฐ๋ฐ ์—ฌ๊ธฐ์„œ package.json์€ ๋ฌด์—‡์ด๊ณ , ๊ฑฐ๊ธฐ๋‹ค package-lock.json์€ ๋ฌด์—‡์ผ๊นŒ?

ํ”„๋กœ์ ํŠธ ์‹œ์ž‘์— ์•ž์„œ ์ผ๋‹จ ๊ตฌ์กฐ๋ถ€ํ„ฐ ์•Œ๊ณ  ์‹œ์ž‘ํ•ด ๋ณด์ž. 

 

 

1. package.json

# package.json ์˜ˆ์‹œ
{
  "name": "codingElla",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
	... # ์ƒ๋žต
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

 

package.json ํŒŒ์ผ์€ Node.js ํ”„๋กœ์ ํŠธ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ํŒŒ์ผ๋กœ, ์ผ๋ฐ˜์ ์œผ๋กœ ์ด ์•ˆ์—๋Š” ํ”„๋กœ์ ํŠธ์˜ ์ด๋ฆ„, ๋ฒ„์ „, ์„ค๋ช…, ์ž‘์„ฑ์ž, ๋ผ์ด์„ผ์Šค, ํ”„๋กœ์ ํŠธ ์‹คํ–‰์— ํ•„์š”ํ•œ ์„œ๋“œํŒŒํ‹ฐ ํŒจํ‚ค์ง€์ธ *์˜์กด์„ฑ ๋ชฉ๋ก์ด ํฌํ•จ๋œ๋‹ค. (์ฐธ๊ณ ๋กœ *์˜์กด์„ฑ์ด๋ž€, ๋ชจ๋“ˆ๊ณผ ๋ชจ๋“ˆ๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ๋‚˜ํƒ€๋‚ด๋ฉฐ ์˜์กด์„ฑ์„ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์€ ์œ ์ง€๋ณด์ˆ˜๋‚˜ ํ™•์žฅ์„ฑ์— ์˜ํ–ฅ์„ ๋ฏธ์น˜๋ฏ€๋กœ ์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ์—์„œ ๋งค์šฐ ์ค‘์š”ํ•˜๋‹ค.) 

 

Node.js ํ”„๋กœ์ ํŠธ์—์„œ ํ„ฐ๋ฏธ๋„์— 'npm install'๋ผ๊ณ  ์ž…๋ ฅํ•˜๋ฉด package.json ํŒŒ์ผ์— ๋‚˜์—ด๋œ ์˜์กด์„ฑ์ด ์ž๋™์œผ๋กœ ์„ค์น˜๋˜๋ฏ€๋กœ ํ”„๋กœ์ ํŠธ์˜ ์˜์กด์„ฑ์„ ์‰ฝ๊ฒŒ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๊ณ , ํ•„์š”ํ•œ ํŒจํ‚ค์ง€์˜ ๋™์ผํ•œ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“  ์‚ฌ์šฉ์ž๋ฅผ ๋ณด์žฅํ•  ์ˆ˜ ์žˆ๋‹ค. (์ด ๋ง์€ ์ง€๊ธˆ์€ ์ดํ•ด๊ฐ€ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์•„๋ž˜์—์„œ ์ž์„ธํ•˜๊ฒŒ ์„ค๋ช…ํ•˜๊ฒ ๋‹ค.)

 

 

2. package-lock.json

# package-lock.json ์˜ˆ์‹œ
{
  "name": "codingElla",
  "version": "0.1.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "codingElla",
      "version": "0.1.0",
      "dependencies": {
        "@testing-library/jest-dom": "^5.16.5",
        "@testing-library/react": "^13.4.0",
        "@testing-library/user-event": "^13.5.0",
        "react": "^18.2.0",
        "react-dom": "^18.2.0",
        "react-scripts": "5.0.1",
        "web-vitals": "^2.1.4"
      }
    },
    "node_modules/@adobe/css-tools": {
      "version": "4.2.0",
      "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.2.0.tgz",
      "integrity": "sha512-E09FiIft46CmH5Qnjb0wsW54/YQd69LsxeKUOWawmws1XWvyFGURnAChH0mlr7YPFR1ofwvUQfcL0J3lMxXqPA=="
    },
    ... # ์ƒ๋žต
  }
}

 

package-lock.jsonํŒŒ์ผ์€ ์˜์กด์„ฑ ํŠธ๋ฆฌ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ,  package-lock.json ํŒŒ์ผ์ด ์ž‘์„ฑ๋œ ์‹œ์ ์˜ ์˜์กด์„ฑ ํŠธ๋ฆฌ๊ฐ€ ๋‹ค์‹œ ์ƒ์„ฑ๋  ์ˆ˜ ์žˆ๋‹ค. (์ด ๋ง ๋˜ํ•œ ์ง€๊ธˆ์€ ์ดํ•ดํ•˜๊ธฐ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์œผ๋‹ˆ ์•„๋ž˜์— ์ž์„ธํ•œ ์„ค๋ช…์„ ํ•˜๊ฒ ๋‹ค.)

 

 

3. package-lock.json๊ฐ€ ํ•„์š”ํ•œ ์ด์œ 

package.json ํŒŒ์ผ ์•ˆ์—์„œ ์˜์กด์„ฑ ์„ ์–ธ์—๋Š” 'version range'๊ฐ€ ์‚ฌ์šฉ๋œ๋‹ค. ์ด๋Š” ํŠน์ • ๋ฒ„์ „์„ ์ง€์นญํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, 'ํŠน์ • ๋ฒ„์ „ ์ด์ƒ'์ด๋ผ๋Š” range๋ฅผ ๋งํ•ด์ค€๋‹ค. (ex. ^18.2.0 === 18.2.0 ๋ฒ„์ „ ์ด์ƒ)

 

์ด๋•Œ package.json ํŒŒ์ผ๋กœ npm install์„ ์ž…๋ ฅํ•˜๋ฉด ํ˜„์žฌ๋Š” 18.2.0 ๋ฒ„์ „์˜ ๋ฆฌ์•กํŠธ๊ฐ€ ์„ค์น˜๋˜์ง€๋งŒ, ์ƒˆ๋กœ์šด ํŒจ์น˜๊ฐ€ ํผ๋ธ”๋ฆฌ์‹œ๋œ๋‹ค๋ฉด ๋™์ผํ•œ package.json ํŒŒ์ผ๋กœ npm install์„ ์ž…๋ ฅํ•ด๋„ ์ด์ „์— ์„ค์น˜ํ•œ 18.2.0 ๋ฒ„์ „์ด ์„ค์น˜๋œ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ์—๋Š” ํฐ ๋ฌธ์ œ๊ฐ€ ์—†์œผ๋‚˜, ์ด๋Š” ๊ฐ„ํ˜น ํ˜‘์—… ํ”„๋กœ์ ํŠธ ์‹œ ์˜ค๋ฅ˜๋ฅผ ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. 

 

# ์ดํ•ด๋ฅผ ๋•๊ธฐ ์œ„ํ•ด ์•„๋ž˜์— ์˜์กด์„ฑ ํŠธ๋ฆฌ ์˜ˆ์‹œ๋ฅผ ์ฒจ๋ถ€ํ•ฉ๋‹ˆ๋‹ค. 
# ์˜์กด์„ฑ ํŠธ๋ฆฌ๋Š” 'npm ls'๋กœ ์กฐํšŒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

codingElla@0.1.0 /Users/yeonsuchoi/Workspace/React/blog-project
โ”œโ”€โ”€ @testing-library/jest-dom@5.16.5
โ”œโ”€โ”€ @testing-library/react@13.4.0
โ”œโ”€โ”€ @testing-library/user-event@13.5.0
โ”œโ”€โ”€ react-dom@18.2.0
โ”œโ”€โ”€ react-scripts@5.0.1
โ”œโ”€โ”€ react@18.2.0
โ””โ”€โ”€ web-vitals@2.1.4

 

์ด๋•Œ, package-lock.json ํŒŒ์ผ์€ ์œ„์™€ ๊ฐ™์€ ์˜์กด์„ฑ ํŠธ๋ฆฌ์— ๋Œ€ํ•œ ์ •๋ณด, ์ฆ‰ ์ •ํ™•ํ•œ ๋ฒ„์ „ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— package-lock.json ํŒŒ์ผ์ด ์ž‘์„ฑ๋œ ์‹œ์ ์˜ ์˜์กด์„ฑ ํŠธ๋ฆฌ๊ฐ€ ๋‹ค์‹œ ์ƒ์„ฑ๋  ์ˆ˜ ์žˆ๋„๋ก ๋ณด์žฅํ•œ๋‹ค.

 

โœ”๏ธ ์˜ˆ๋ฅผ ๋“ค์–ด,

1. 4์›” 1์ผ์— 18.2.0 ๋ฒ„์ „์„ ์„ค์น˜ํ–ˆ๊ณ 

2. 4์›” 30์ผ์— npm install์„ ํ•˜์—ฌ ์—…๋ฐ์ดํŠธ๋œ 18.3.0 ๋ฒ„์ „์„ ์„ค์น˜ํ•˜๊ณ ์ž ํ•˜๋”๋ผ๋„

3. package-lock.json ํŒŒ์ผ ๋•๋ถ„์— 18.2.0 ๋ฒ„์ „์œผ๋กœ ์˜์กด์„ฑ ํŠธ๋ฆฌ๊ฐ€ ๋‹ค์‹œ ์—…๋ฐ์ดํŠธ ๋˜๋Š” ๊ฒƒ์ด๋‹ค. (์‚ฌ์‹ค ์ด ๊ณผ์ •์€ package.json์˜ ์กด์žฌ๋งŒ์œผ๋กœ๋„ ๊ฐ€๋Šฅํ•˜๋‚˜, package-lock.json์ด ์ •ํ™•ํ•œ ๋ฒ„์ „ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํŠนํžˆ ํ˜‘์—… ์‹œ ํ•„์š”ํ•œ ์กด์žฌ๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค.)

 

package.json and package-lock.json @Atatus

 

โœ”๏ธ ๋•Œ๋ฌธ์—,

์œ„ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ํ˜‘์—…์„ ์œ„ํ•ด์„œ๋Š” package.json ํŒŒ์ผ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ package-lock.json ๋˜ํ•œ ํ•จ๊ป˜ ์ปค๋ฐ‹ํ•ด์•ผ ํ•œ๋‹ค.

 

โœ”๏ธ ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด,

1. ๋‚ด๊ฐ€ 4์›” 1์ผ์— ๋‚ด๊ฐ€ ์ปค๋ฐ‹ํ•œ ์†Œ์Šค์ฝ”๋“œ๋ฅผ

2. ๋™๋ฃŒ ๊ฐœ๋ฐœ์ž๊ฐ€ 4์›” 30์ผ์— pull ํ•œ ํ›„ npm install์„ ์‹คํ–‰ํ•˜๋ฉด

3. ๋‚˜์˜ ์˜์กด์„ฑ ํŠธ๋ฆฌ์™€ ๋™๋ฃŒ์˜ ์˜์กด์„ฑ ํŠธ๋ฆฌ๊ฐ€ ๋‹ค๋ฅด๊ฒŒ ์„ค์น˜๋˜์–ด ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ์‹œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด๋‹ค.

 

โœ”๏ธ ์ •๋ฆฌํ•˜์ž๋ฉด,

package-lock.json ํŒŒ์ผ ์•ˆ์—๋Š” ํ”„๋กœ์ ํŠธ์˜ ์˜์กด์„ฑ ํŠธ๋ฆฌ๋ฅผ ํฌํ•จํ•œ ๊ฐ ์˜์กด์„ฑ์˜ ์ •ํ™•ํ•œ ๋ฒ„์ „, ๋ฒ„์ „ ์ถฉ๋Œ ๋“ฑ์˜ ์ •๋ณด๊ฐ€ ํฌํ•จ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์„ค์น˜ ๋‹น์‹œ ์˜์กด์„ฑ์„ ์žฌํ˜„ํ•˜๊ณ , ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž์™€ ๊ณต์œ ํ•  ๋•Œ ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๋Š” ๋ฐ์— ์‚ฌ์šฉ๋œ๋‹ค.

 

๋”ฐ๋ผ์„œ package-lock.json ํŒŒ์ผ์„ Github ๋“ฑ ๋ฒ„์ „ ๊ด€๋ฆฌ ์‹œ์Šคํ…œ์— ์œ ์ง€ํ•˜๊ณ  ์‚ญ์ œํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. 

 

 

4. ์ถ”๊ฐ€ ๊ถ๊ธˆ์ฆ

๐Ÿค” package-lock.json ํŒŒ์ผ์„ ์‚ญ์ œํ•˜๋ฉด ์˜์กด์„ฑ ํŠธ๋ฆฌ๋‚˜ ์„ค์น˜๋œ ์˜์กด์„ฑ์ด ์‚ญ์ œ๋ ๊นŒ?

package-lock.json ํŒŒ์ผ์„ ์‚ญ์ œํ•˜๋ฉด ์˜์กด์„ฑ ํŠธ๋ฆฌ๋‚˜ ์„ค์น˜๋œ ์˜์กด์„ฑ์ด ์‚ญ์ œ๋˜์ง€๋Š” ์•Š๋Š”๋‹ค. ์•ž์„œ ์ด์•ผ๊ธฐํ•œ ๊ฒƒ์ฒ˜๋Ÿผ package-lock.json ํŒŒ์ผ์€ ์„ค์น˜๋œ ํŒจํ‚ค์ง€๊ฐ€ package.json ํŒŒ์ผ์—์„œ ์ง€์ •๋œ ์ •ํ™•ํ•œ ๋ฒ„์ „๊ณผ ์ผ์น˜ํ•˜๋„๋ก ๋ณด์žฅํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋œ๋‹ค. package-lock.json ํŒŒ์ผ์ด ์‚ญ์ œ๋˜๋ฉด npm์€ ์—ฌ์ „ํžˆ package.json ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ•„์š”ํ•œ ์˜์กด์„ฑ์„ ์„ค์น˜ํ•˜์ง€๋งŒ, ์ •ํ™•ํžˆ ๊ฐ™์€ ๋ฒ„์ „์„ ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์„ ๋ณด์žฅํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด๋ผ ๋ณด๋ฉด ๋œ๋‹ค.

๐Ÿค” ์• ์ดˆ์— package.json ํŒŒ์ผ์— ์ •ํ™•ํ•œ ๋ฒ„์ „๋ช…์„ ์ ์–ด๋‘๋ฉด ๋˜์ง€ ์•Š์„๊นŒ?

package.json ํŒŒ์ผ์— ์ •ํ™•ํ•œ ํŒจํ‚ค์ง€ ๋ฒ„์ „๋ช…์„ ๋ช…์‹œํ•œ๋‹ค๋ฉด,  ํ”„๋กœ์ ํŠธ์—์„œ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ํŒจํ‚ค์ง€์˜ ์ค‘์š”ํ•œ ๋ฒ„๊ทธ ์ˆ˜์ •์ด ์ด๋ฃจ์–ด์งˆ ๋•Œ๋งˆ๋‹ค ํ”„๋กœ์ ํŠธ์˜ package.json ํŒŒ์ผ์— ์ ํ˜€์žˆ๋Š” ๋ฒ„์ „๋„ ์ˆ˜์ •์„ ํ•ด์•ผ ํ•˜๋Š” ๋ฒˆ๊ฑฐ๋กœ์›€์ด ์ƒ๊ธธ ์ˆ˜ ์žˆ๋‹ค. ์ฆ‰, ํฌ๊ณ  ์ž‘์€ ํŒจํ‚ค์ง€๋“ค์˜ ๋ฆด๋ฆฌ์ฆˆ์— ๋Œ€ํ•ด ํ•ญ์ƒ ์ถ”์ ํ•˜๊ณ  ์ˆ˜์ •ํ•ด์•ผ ํ•˜๋Š” ๋ฒˆ๊ฑฐ๋กœ์›€์„ version range๋กœ ๋ช…์‹œํ•จ์œผ๋กœ์จ ์ด๋ฅผ ํ•ด๊ฒฐํ•ด ์ฃผ๋Š” ๊ฒƒ์ด๋ผ๊ณ  ๋ณด๋ฉด ๋œ๋‹ค.

 

 

5. References

- package-lock.json์€ ์™œ ํ•„์š”ํ• ๊นŒ?

- Package.json๊ณผ Package-lock.json์˜ ์ฐจ์ด๋ฅผ ์•„์‹œ๋‚˜์š”?

- Caret vs Tilde in package.json
- npm ๊ณต์‹๋ฌธ์„œ: package-lock.json

 

 

 

๋Œ“๊ธ€