Migrate a Node.js project from NPM to PNPM
Install pnpm
:
# on Mac
❯ brew install pnpm
# with node.js installed
❯ npm install -g pnpm
Steps
# Remove existing dependencies and the NPM lock file
❯ rm -rf node_modules package-lock.json
# Install dependencies
❯ pnpm install
Update Scripts
npm run test
=>pnpm test
npm start
=>pnpm start
npx prisma migrate dev --name "$1" --schema=app/prisma/schema.prisma
=>pnpm dlx prisma migrate dev --name "$1" --schema=app/prisma/schema.prisma
Update Dockerfile
Install PNPM
and migrate related commands:
RUN npm install -g pnpm@latest-10
RUN pnpm install
RUN pnpm dlx prisma generate --schema=app/prisma/schema.prisma
CMD ["pnpm", "start"]
Update CI/CD
- Use
pnpm/action-setup
- Use cache to reduce installation time
on:
- push
- pull_request
jobs:
deploy:
name: Deploy to AWS ECS - ${{ inputs.environment }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
run_install: false
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22.x"
cache: "pnpm"