15

The official Next.js Dockerfile example does not work if I switch npm to pnpm.

How should I modify that Dockerfile so that it remains multi-stage, but also uses pnpm instead of npm?

Meglio
  • 1,646
  • 2
  • 17
  • 33
  • 1
    There is no `npm` in that [Dockerfile](https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile); it is using Yarn. What exactly have you changed, and what is the error you're experiencing? Please add necessary details in the questions. The change should be direct - `yarn build` to `pnpm run build`, `yarn` to `pnpm`, `yarn.lock` to `pnpm-lock.yaml`. What is causing issue? `pnpm` is just a package manager, it should not cause problems as such. – brc-dd Aug 04 '21 at 14:30
  • 3
    As @brc-dd mentioned, it's hard to tell if we don't know what's the error you're seeing. That being said, you may need to install `pnpm` within the Docker container before using it: `RUN npm install -g pnpm`. – juliomalves Aug 04 '21 at 22:17

4 Answers4

19

Another solution is installing pnpm using npm. When you install nodejs it comes with npm as the default package manager. So you can install pnpm using npm using the following command npm install -g pnpm

In the docker file it will be written as;

RUN npm install -g pnpm
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
7

What worked for me is the following:

FROM node:16-alpine AS base
RUN apk update && apk add --no-cache libc6-compat
RUN corepack enable && corepack prepare pnpm@7.4.1 --activate 
...

The above assumes that you're using either >=Node 16.9 or >=Node 14.19; that has the corepack command built-in.

jayg_code
  • 571
  • 8
  • 21
6

I know I'm a bit late, but this is what worked for me:

RUN apk add --no-cache curl \
    && curl -sL https://unpkg.com/@pnpm/self-installer | node
0

What worked for me is the following:

FROM node:16.16.0-alpine3.16
RUN corepack enable
RUN corepack prepare pnpm@7.18.0 --activate
Tyler2P
  • 2,324
  • 26
  • 22
  • 31