Skip to content

Commit

Permalink
README tweak to make sure nodejs is already in use
Browse files Browse the repository at this point in the history
  • Loading branch information
jasononeil committed Feb 23, 2024
1 parent 4e1ba77 commit f1ffae7
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions plugins/corepack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ When using corepack, running `pnpm` or `yarn` will always use the correct versio

## Use and activation

1. Make sure you already have a `nodejs` listed as one of your packages in `devbox.json`:

```json
{
"packages": ["[email protected]"]
}
```

1. Add this plugin to the `include` section of your `devbox.json`:

```json
{
"packages": ["[email protected]"],
"include": ["github:cultureamp/devbox-extras?dir=plugins/corepack"]
}
```
Expand All @@ -30,6 +39,8 @@ or
}
```

When you run `pnpm -v` or `yarn -v` you should see that the versions used match what you've set in the `packageManager` field.

## Motivation

There’s a subtle but messy issue that can arise using Devbox, Node.js, and Yarn/PNPM. If you install node and yarn as documented you will end up with two different versions of node:
Expand All @@ -46,9 +57,13 @@ v18.18.0

This happens because nix bundles all dependencies into every package, yarn is getting it’s own copy of Node.js, which may be more recent than the Node.js version the project is using.

Corepack by default tries to install shim scripts for both `yarn` and `pnpm` in the same directory that `node` is found in. Unfortunately when using devbox, the `node` binary is in the Nix store, which is read only, so Corepack fails to set up correctly.
Corepack is a tool included with Node.js that manages PNPM and Yarn versions for you, installing the requested versions as needed and switching seamlessly. Using Corepack would mean that we don't need Devbox / Nix to provide pnpm or Yarn binaries.

But corepack by default tries to install shim scripts for both `yarn` and `pnpm` in the same directory that `node` is found in. Unfortunately when using devbox, the `node` binary is in the Nix store, which is read only, so Corepack gives an error similar to:

> `Internal Error: EACCES: permission denied, unlink '/nix/store/0r6wvd9rr6lsrv8j9b3nv9s9lw7vfb37-profile/bin/pnpm'`
This plugin works by:
This Devbox plugin works by:

- creating a folder in `.devbox/virtenv/pnpm_plugin/bin/`
- running `corepack enable --install-directory "./devbox/virtenv/pnpm_plugin/bin/"`, which adds the `pnpm` and `yarn` shim scripts
Expand Down

0 comments on commit f1ffae7

Please sign in to comment.