dockergithubpnpm

Install GitHub dependency using PNPM in Dockerfile


I'm using pnpm in Dockerfile I have one dependency which is installed from GitHub.
PNPM by default use yarn to install dependency from Git.
Problem with PNPM is it is not able to access the yarn, I think some kind of permission problem.

ERROR:
ERR_PNPM_PREPARE_PKG_FAILURE  Command failed with exit code 1: /usr/local/bin/yarn install
The command '/bin/sh -c pnpm install' returned a non-zero code: 1

Here is my Dockerfile

FROM node:alpine

RUN npm install -g pnpm

WORKDIR /app

COPY ["package.json", "pnpm-lock.yaml", "./"]

RUN pnpm install

COPY . .

RUN pnpm build

ENV PORT=8080

EXPOSE 80

CMD [ "node", "./build/index.js" ]

Update

This is repo that is used from GitHub. Baileys

Everything works perfect when I try to install packages without Dockerfile If I run pnpm install everything just works. But When I run the build command for Dockerfile it will create problem.
docker build -t name .


Solution

  • As you stated, pnpm uses yarn to install dependencies from Git. From your output, you can see that yarn failed. If you run inside Docker container yarn add https://github.com/adiwajshing/Baileys.git, it would output:

    info No lockfile found.
    [1/4] Resolving packages...
    error Couldn't find the binary git
    

    node:alpine image is missing git.


    To resolve your problem, simply install git before pnpm install in Dockerfile:

    FROM node:alpine
    RUN apk add --no-cache git
    RUN npm install -g pnpm
    ...