💻 Programming

Dependency

Dependency

An external library that code requires. Managed with package.json and requirements.txt.

📖 Detailed Explanation

A dependency is an external library, module, or package that software needs in order to operate correctly. In modern software development, it is common to bring in and use proven external code instead of implementing every feature yourself. This dependency-based approach to development greatly increases development speed and improves code quality.

Dependencies are divided into direct dependencies and transitive dependencies. A direct dependency is a package that the project explicitly installs, and a transitive dependency is another package that a direct dependency uses internally. For example, when you install React, loose-envify, js-tokens, and other packages that React depends on are installed along with it.

Each programming language and ecosystem has its own dependency management tools. JavaScript uses npm/yarn/pnpm and package.json, Python uses pip and requirements.txt, Java uses Maven/Gradle, Go uses go mod, and Rust uses Cargo. These package managers provide features such as version management, conflict resolution, and security vulnerability scanning.

Dependency management directly affects a project's stability and security. If versions are not locked, unexpected updates can break the build, and outdated dependencies can contain security vulnerabilities. Therefore, regular dependency updates and security scans are essential elements of modern DevOps pipelines.

💻 Code Example

// === package.json (Node.js/JavaScript) ===
{
  "name": "my-project",
  "version": "1.0.0",
  "dependencies": {
    "express": "^4.18.2",      // 프로덕션 의존성
    "axios": "~1.6.0",         // API 호출 라이브러리
    "lodash": "4.17.21"        // 정확한 버전 고정
  },
  "devDependencies": {
    "jest": "^29.7.0",         // 개발 전용 (테스트)
    "eslint": "^8.56.0"        // 개발 전용 (린터)
  }
}

// === requirements.txt (Python) ===
// pip install -r requirements.txt 로 설치
Flask==2.3.3
requests>=2.31.0,<3.0.0
pandas~=2.0.0
numpy                          # 최신 버전

// === pom.xml (Java/Maven) ===
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>3.2.0</version>
    </dependency>
</dependencies>

// === 버전 지정 기호 의미 ===
// ^4.18.2  : 4.x.x (메이저 버전 고정)
// ~1.6.0   : 1.6.x (마이너 버전 고정)
// 4.17.21  : 정확히 이 버전만
// >=2.0.0  : 2.0.0 이상

// === 의존성 관리 명령어 ===
// npm install           # package.json 기반 설치
// npm update            # 패키지 업데이트
// npm audit             # 보안 취약점 검사
// npm audit fix         # 자동 보안 수정
// npm outdated          # 업데이트 가능한 패키지 확인

🗣️ Say It Like This in Practice

💬 In a Meeting
"I ran a dependency security audit before this release, and a prototype pollution vulnerability was found in lodash. We need to update to the latest version and regenerate package-lock.json as well."
💬 In an Interview
"In dependency version management, the caret (^) locks the major version, and the tilde (~) locks up to the minor version. In production, always commit the lock file so that the same versions are installed in every environment. We also manage security updates automatically through Dependabot or Renovate."
💬 In a code review
"moment.js has been added to the dependencies, but its bundle size is large and it is no longer maintained. If you replace it with date-fns or dayjs, you can reduce the bundle size by more than 90%. They also support tree-shaking, so only the functions you use are included."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
The mistake of not committing the lock file

The package-lock.json, yarn.lock, and poetry.lock files must be included in version control. Without these files, different versions get installed in the development, test, and production environments, causing the "it works on my machine" problem.

❌
Neglecting unnecessary dependencies

Leaving unused packages as they are increases the bundle size and the risk of exposure to security vulnerabilities. Use tools such as depcheck and npm-check to regularly clean up unused dependencies.

✅
Automated security vulnerability monitoring

Integrate GitHub Dependabot, Snyk, and npm audit into your CI/CD pipeline so that vulnerabilities are automatically detected and PRs are created. It is important to apply security updates as soon as possible.

🔗 Related Terms

📚 Learn More