Skip to main content
Version: Next

よくある質問 (FAQ)

なぜ、 node_modules フォルダは、パッケージがグローバルストアに保存されている場合にディスク容量を使用するのですか?#

pnpm は、 ハードリンク を、グローバルストアからプロジェクトの node_modules フォルダーに作成します。 ハードリンクは、元の ファイルがあるディスク上の同じ場所を指します。 例えば、1MBを占める foo を依存に持つプロジェクトでは、そのプロジェクト配下の node_modules フォルダが、リンク元のグローバルストアと同じ 1MB を消費しているように見えます。 ただし、2つの異なるリンクが示す、占有されている 1MB はディスク上の 同じ位置 にあります。 そのため、全体で foo は 2MB ではなく 1MB のみ占有しています。



簡単な答え:はい。 詳細な答え: Windows 上でシンボリックリンクを使用することに関しては少なくとも問題はありますが、しかし、pnpm には回避策があります。 Windows では、代わりに ジャンクション を使用します。

しかし、ネストされた node_modules アプローチは Windows と互換性がありますか?#

npm の初期のバージョンはすべての node_modules を入れ子にするために問題がありました ( この issue を参照してください)。 However, pnpm does not create deep folders, it stores all packages flatly and uses symbolic links to create the dependency tree structure.

What about circular symlinks?#

Although pnpm uses linking to put dependencies into node_modules folders, circular symlinks are avoided because parent packages are placed into the same node_modules folder in which their dependencies are. So foo's dependencies are not in foo/node_modules, but foo is in node_modules together with its own dependencies.

Why have hard links at all? Why not symlink directly to the global store?#

One package can have different sets of dependencies on one machine.

In project A [email protected] can have a dependency resolved to [email protected], but in project B the same dependency of foo might resolve to [email protected]; so, pnpm hard links [email protected] to every project where it is used, in order to create different sets of dependencies for it.

Direct symlinking to the global store would work with Node's --preserve-symlinks flag, however, that approach comes with a plethora of its own issues, so we decided to stick with hard links. For more details about why this decision was made, see this issue.

Does pnpm work across multiple drives or filesystems?#

The package store should be on the same drive and filesystem as installations, otherwise packages will be copied, not linked. This is due to a limitation in how hard linking works, in that a file on one filesystem cannot address a location in another. See Issue #712 for more details.

pnpm functions differently in the 2 cases below:

Store path is specified#

If the store path is specified via the store config, then copying occurs between the store and any projects that are on a different disk.

If you run pnpm install on disk A, then the pnpm store must be on disk A. If the pnpm store is located on disk B, then all required packages will be directly copied to the project location instead of being linked. This severely inhibits the storage and performance benefits of pnpm.

Store path is NOT specified#

If the store path is not set, then multiple stores are created (one per drive or filesystem).

If installation is run on disk A, the store will be created on A .pnpm-store under the filesystem root. If later the installation is run on disk B, an independent store will be created on B at .pnpm-store. The projects would still maintain the benefits of pnpm, but each drive may have redundant packages.

What does pnpm store prune do? Is it harmful?#

The command pnpm store prune removes unreferenced packages.

Unreferenced packages are packages that are not used by any projects on the system. Packages can become unreferenced after most installation operations, for instance when dependencies are made redundant.

For example, during pnpm install, package [email protected] is updated to [email protected]. pnpm will keep [email protected] in the store, as it does not automatically remove packages. If package [email protected] is not used by any other project on the system, it becomes unreferenced. Running pnpm store prune would remove [email protected] from the store.

Running pnpm store prune is not harmful and has no side effects on your projects. If future installations require removed packages, pnpm will download them again.

It is best practice to run pnpm store prune occasionally to clean up the store, but not too frequently. Sometimes, unreferenced packages become required again. This could occur when switching branches and installing older dependencies, in which case pnpm would need to re-download all removed packages, briefly slowing down the installation process.

What does pnpm stand for?#

pnpm stands for performant npm. @rstacruz came up with the name.

pnpm does not work with <YOUR-PROJECT-HERE>?#

In most cases it means that one of the dependencies require packages not declared in package.json. It is a common mistake caused by flat node_modules. If this happens, this is an error in the dependency and the dependency should be fixed. That might take time though, so pnpm supports workarounds to make the buggy packages work.

Solution 1#

In the following example, a dependency does not have the iterall module in its own list of deps.

The easiest solution to resolve missing dependencies of the buggy packages is to add iterall as a dependency to our project's package.json.

You can do so, by installing it via pnpm add iterall, and will be automatically added to your project's package.json.

  "dependencies": {    ...    "iterall": "^1.2.2",    ...  }

Solution 2#

One of the solutions is to use hooks for adding the missing dependencies to the package's package.json.

An example was Webpack Dashboard which wasn't working with pnpm. It has since been resolved such that it works with pnpm now.

It used to throw an error:

Error: Cannot find module 'babel-traverse'  at /node_modules/[email protected]/node_modules/inspectpack/lib/actions/parse

The problem was that babel-traverse was used in inspectpack which was used by webpack-dashboard, but babel-traverse wasn't specified in inspectpack's package.json. It still worked with npm and yarn because they create flat node_modules.

The solution was to create a .pnpmfile.cjs with the following contents:

module.exports = {  hooks: {    readPackage: (pkg) => {      if ( === "inspectpack") {        pkg.dependencies['babel-traverse'] = '^6.26.0';      }      return pkg;    }  }};

After creating a .pnpmfile.cjs, delete pnpm-lock.yaml only - there is no need to delete node_modules, as pnpm hooks only affect module resolution. Then, rebuild the dependencies & it should be working.

Solution 3#

In case there are too many issues, you can use the shamefully-hoist option. This creates a flat node_modules structure similar to the one created by npm or yarn, which is not recommended as avoiding this structure is the primary purpose of pnpm's node_modules approach.

To use it, try pnpm install --shamefully-hoist.