常見問題
Why does my node_modules
folder use disk space if packages are stored in a global store?
pnpm creates hard links from the global store to the project's node_modules
folders. 硬連結會指向硬碟上原始檔所在的同一位置。 So, for example, if you have foo
in your project as a dependency
and it occupies 1MB of space, then it will look like it occupies 1MB of space in
the project's node_modules
folder and the same amount of space in the global
store. However, that 1MB is the same space on the disk addressed from two
different locations. So in total foo
occupies 1MB, not 2MB.
有關這個主題的更多資訊:
- Why do hard links seem to take the same space as the originals?
- A thread from the pnpm chat room
- An issue in the pnpm repo
pnpm 可以在 Windows 上執行嗎?
一句話:是的。 詳細回答:在 Windows 上使用符號連結會造成許多問題,但 pnpm 有一個暫時的解決方法。 For Windows, we use junctions instead.
But the nested node_modules
approach is incompatible with Windows?
Early versions of npm had issues because of nesting all node_modules
(see
this 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.
為什麼使用硬連結? 為什麼不直接 symlink 至全域的儲存區?
一個包在一台機器上可以有不同的依賴集。
In project A foo@1.0.0
can have a dependency resolved to bar@1.0.0
, but
in project B the same dependency of foo
might resolve to bar@1.1.0
; so,
pnpm hard links foo@1.0.0
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 different subvolumes in one Btrfs partition?
While Btrfs does not allow cross-device hardlinks between different subvolumes in a single partition, it does permit reflinks. As a result, pnpm utilizes reflinks to share data between these subvolumes.
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:
已指定儲存區路徑
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.
未指定儲存區路徑
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
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.