Meglio
Meglio

Reputation: 1765

How to pnpm and Next.js in multi-stage docker file?

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?

Upvotes: 18

Views: 27615

Answers (4)

Bruno Sampaio
Bruno Sampaio

Reputation: 11

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

Upvotes: 1

jayg_code
jayg_code

Reputation: 609

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.

Upvotes: 9

James Kaguru Kihuha
James Kaguru Kihuha

Reputation: 543

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

Upvotes: 25

stevenscoville
stevenscoville

Reputation: 71

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

Upvotes: 7

Related Questions