# package.json Standards
## Rule
Every package.json MUST have name, version, description, and license fields. Dependencies MUST use appropriate version ranges. Scripts MUST follow consistent naming conventions.
## Required Fields
```json
{
"name": "@myorg/my-package",
"version": "1.0.0",
"description": "Brief description of what this package does",
"license": "MIT",
"type": "module",
"engines": {
"node": ">=20.0.0"
}
}
```
## Script Naming Conventions
```json
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write .",
"format:check": "prettier --check .",
"typecheck": "tsc --noEmit",
"precommit": "lint-staged"
}
}
```
## Dependency Classification
| Type | Category | Example |
|------|----------|---------|
| Runtime dependency | dependencies | express, react, lodash |
| Build/test tool | devDependencies | jest, eslint, typescript |
| Peer requirement | peerDependencies | react (for React plugins) |
## Good Examples
```json
{
"name": "@myorg/api-server",
"version": "2.1.0",
"description": "REST API server for the myorg platform",
"license": "MIT",
"type": "module",
"engines": { "node": ">=20.0.0" },
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "tsc",
"start": "node dist/index.js",
"test": "vitest run",
"lint": "eslint src/"
},
"dependencies": {
"express": "^4.18.2",
"zod": "^3.22.0"
},
"devDependencies": {
"typescript": "^5.4.0",
"vitest": "^1.5.0",
"eslint": "^9.0.0"
}
}
```
## Bad Examples
```json
{
"name": "app",
"scripts": { "go": "node index.js" },
"dependencies": {
"jest": "^29.0.0",
"typescript": "^5.0.0",
"express": "*"
}
}
```
## Enforcement
- Use `npm pkg fix` to auto-correct common issues
- `npm publish --dry-run` to verify package contents
- CI validates engines field matches runtime version