From 6900384c1bd2d2ce42c31ae72bc0f37e44faa10c Mon Sep 17 00:00:00 2001 From: adisbladis Date: Thu, 27 Mar 2025 12:56:37 +0100 Subject: [PATCH] doc/importNpmLock.buildNodeModules: Add note regarding package-lock-only When using `buildNodeModules` to create `node_modules` commands like `npm install` & `npm add` that writes packages & executables needs to be used with `--package-lock-only`. --- doc/languages-frameworks/javascript.section.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/languages-frameworks/javascript.section.md b/doc/languages-frameworks/javascript.section.md index 9acfd4181108..354fa000d1ba 100644 --- a/doc/languages-frameworks/javascript.section.md +++ b/doc/languages-frameworks/javascript.section.md @@ -369,6 +369,15 @@ pkgs.mkShell { ``` will create a development shell where a `node_modules` directory is created & packages symlinked to the Nix store when activated. +:::{.note} +Commands like `npm install` & `npm add` that writes packages & executables needs to be used with `--package-lock-only`. + +This means `npm` installs dependencies by writing into `package-lock.json` without modifying the `node_modules` folder. Installation happens through reloading the devShell. +This might be best practice since it gives the `nix shell` virtually exclusive ownership over your `node_modules` folder. + +It's recommended to set `package-lock-only = true` in your project-local [`.npmrc`](https://docs.npmjs.com/cli/v11/configuring-npm/npmrc). +::: + ### corepack {#javascript-corepack} This package puts the corepack wrappers for pnpm and yarn in your PATH, and they will honor the `packageManager` setting in the `package.json`.