Skip to content

Instantly share code, notes, and snippets.

@fuji44
Last active March 30, 2023 12:53
Show Gist options
  • Save fuji44/1d9893029b70f1cb1cdeb42f82c6976b to your computer and use it in GitHub Desktop.
Save fuji44/1d9893029b70f1cb1cdeb42f82c6976b to your computer and use it in GitHub Desktop.
Addressing the issue of .pnpm-store being created in the project root in Devcontainer

What to do when .pnpm-store is created in the project root

When I tried to use pnpm with devcontainer, a .pnpm-store was created in the project root. It should normally be created in an appropriate path under the home directory.

This directory contains the npm package entities. My understanding is that this is a characteristic of pnpm and it is not in line with pnpm's philosophy to create it in the project root.

Solution

Explicitly specify store-dir in pnpm.

pnpm config set -g store-dir "${HOME}/.local/share/pnpm/store"

Set postCreateCommand in devcontainer.json to run this after devcontainer creation.

// .devcontainer/devcontainer.json

{
// ...
  "postCreateCommand": ".devcontainer/postCreate.sh",
// ...
}

Contents of .devcontainer/postCreate.sh.

# .devcontainer/postCreate.sh

#! /usr/bin/env bash

pnpm config set -g store-dir "${HOME}/.local/share/pnpm/store"
pnpm install

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment