|
| 1 | +# Package Manager and Node.js Requirements |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This project enforces specific requirements for the development environment to ensure consistency across all contributors and deployments. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +### Node.js Version |
| 10 | + |
| 11 | +- **Minimum required version**: v20.3.0 |
| 12 | +- **Recommended version**: v22.x (LTS) |
| 13 | + |
| 14 | +This requirement is based on Astro's compatibility with Node.js versions. Astro 5.x requires Node.js v20.3.0 or higher. |
| 15 | + |
| 16 | +### Package Manager |
| 17 | + |
| 18 | +- **Required package manager**: pnpm v8.0.0 or higher |
| 19 | +- **Current version used**: pnpm v8.15.4 |
| 20 | + |
| 21 | +## Why pnpm? |
| 22 | + |
| 23 | +We've chosen pnpm as the required package manager for this project for several reasons: |
| 24 | + |
| 25 | +1. **Disk space efficiency**: pnpm uses a content-addressable store which saves disk space and speeds up installation. |
| 26 | +2. **Strict dependency resolution**: pnpm creates a non-flat `node_modules` structure that prevents access to packages that aren't explicitly declared as dependencies. |
| 27 | +3. **Performance**: pnpm is generally faster than npm and Yarn Classic for installation operations. |
| 28 | +4. **Consistency**: Using a single package manager ensures consistent dependency resolution across all development environments. |
| 29 | + |
| 30 | +## Configuration Files |
| 31 | + |
| 32 | +The following files enforce these requirements: |
| 33 | + |
| 34 | +- `.nvmrc`: Specifies the Node.js version for tools like nvm |
| 35 | +- `.npmrc`: Contains npm-related configurations |
| 36 | +- `.pnpmrc`: Contains pnpm-specific configurations |
| 37 | +- `package.json`: Contains the `engines` and `packageManager` fields |
| 38 | + |
| 39 | +## Enforcement |
| 40 | + |
| 41 | +These requirements are enforced through: |
| 42 | + |
| 43 | +1. The `engines` field in `package.json` |
| 44 | +2. The `packageManager` field in `package.json` |
| 45 | +3. A simple preinstall script that prevents npm/yarn usage |
| 46 | +4. Configuration in `.npmrc` and `.pnpmrc` |
| 47 | + |
| 48 | +## Installation |
| 49 | + |
| 50 | +Since we require Node.js 20.3.0 or higher, we recommend using Corepack to manage pnpm. Corepack is included with Node.js 20+ and provides native package manager version management. |
| 51 | + |
| 52 | +### Using Corepack (Recommended) |
| 53 | + |
| 54 | +```bash |
| 55 | +# Enable Corepack (only needed once) |
| 56 | +corepack enable |
| 57 | + |
| 58 | +# Use the latest pnpm version |
| 59 | +corepack prepare pnpm@latest --activate |
| 60 | +``` |
| 61 | + |
| 62 | +This approach has several advantages: |
| 63 | +1. No need to install pnpm globally |
| 64 | +2. Automatically uses the correct version specified in package.json |
| 65 | +3. Built into Node.js 20+ |
| 66 | +4. Ensures consistent package manager versions across all developers |
| 67 | + |
| 68 | +### Alternative Installation |
| 69 | + |
| 70 | +If you prefer not to use Corepack, you can install pnpm globally: |
| 71 | + |
| 72 | +```bash |
| 73 | +npm install -g pnpm |
| 74 | +``` |
| 75 | + |
| 76 | +## Troubleshooting |
| 77 | + |
| 78 | +### Common Issues |
| 79 | + |
| 80 | +If you encounter issues related to Node.js version or package manager: |
| 81 | + |
| 82 | +1. Check your Node.js version with `node -v` |
| 83 | +2. Install the required Node.js version |
| 84 | +3. Enable Corepack with `corepack enable` |
| 85 | +4. Prepare pnpm with `corepack prepare pnpm@latest --activate` |
| 86 | +5. Use `pnpm install` to install dependencies |
| 87 | + |
| 88 | +### Network Issues with Corepack |
| 89 | + |
| 90 | +If you encounter network errors when Corepack tries to download pnpm (especially during git commits with Husky): |
| 91 | + |
| 92 | +``` |
| 93 | +Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-8.15.4.tgz. |
| 94 | +Internal Error: Error when performing the request... |
| 95 | +``` |
| 96 | + |
| 97 | +Try these solutions: |
| 98 | + |
| 99 | +1. **Install pnpm globally** as a fallback: |
| 100 | + ```bash |
| 101 | + |
| 102 | + ``` |
| 103 | + This is the simplest solution and recommended for most users. |
| 104 | + |
| 105 | +2. **Configure npm registry** if you're behind a proxy or firewall: |
| 106 | + ```bash |
| 107 | + npm config set registry https://registry.npmjs.org/ |
| 108 | + ``` |
| 109 | + |
| 110 | +3. **Disable Husky temporarily** if needed for commits: |
| 111 | + ```bash |
| 112 | + git commit --no-verify -m "Your commit message" |
| 113 | + ``` |
| 114 | + |
| 115 | +4. **Check network connectivity** to registry.npmjs.org |
| 116 | + |
| 117 | +For more information on pnpm, visit [the official pnpm documentation](https://pnpm.io/). |
| 118 | + |
| 119 | +For more information on Corepack, visit [the Node.js Corepack documentation](https://nodejs.org/api/corepack.html) and [Corepack Troubleshooting](https://github.com/nodejs/corepack#troubleshooting). |
0 commit comments