Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Version: 10.x

Frequently Asked Questions

Why does mynode_modules folder use disk space if packages are stored in a global store?

pnpm createshard links from the global store to the project'snode_modulesfolders. Hard links point to the same place on the disk where the originalfiles are. So, for example, if you havefoo in your project as a dependencyand it occupies 1MB of space, then it will look like it occupies 1MB of space inthe project'snode_modules folder and the same amount of space in the globalstore. However, that 1MB isthe same space on the disk addressed from twodifferent locations. So in totalfoo occupies 1MB, not 2MB.

For more on this subject:

Does it work on Windows?

Short answer: Yes.Long answer: Using symbolic linking on Windows is problematic to say the least,however, pnpm has a workaround. For Windows, we usejunctions instead.

But the nestednode_modules approach is incompatible with Windows?

Early versions of npm had issues because of nesting allnode_modules (seethis issue). However, pnpm does not create deep folders, it stores all packagesflatly and uses symbolic links to create the dependency tree structure.

What about circular symlinks?

Although pnpm uses linking to put dependencies intonode_modules folders,circular symlinks are avoided because parent packages are placed into the samenode_modules folder in which their dependencies are. Sofoo's dependenciesare not infoo/node_modules, butfoo is innode_modules together with itsown 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 projectAfoo@1.0.0 can have a dependency resolved tobar@1.0.0, butin projectB the same dependency offoo might resolve tobar@1.1.0; so,pnpm hard linksfoo@1.0.0 to every project where it is used, in order tocreate 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 itsown issues, so we decided to stick with hard links. For more details about whythis decision was made, seethis 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 inhow hard linking works, in that a file on one filesystem cannot address alocation in another. SeeIssue #712 for more details.

pnpm functions differently in the 2 cases below:

Store path is specified

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

If you runpnpm install on diskA, then the pnpm store must be on diskA.If the pnpm store is located on diskB, then all required packages will bedirectly copied to the project location instead of being linked. This severelyinhibits 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 orfilesystem).

If installation is run on diskA, the store will be created onA.pnpm-store under the filesystem root. If later the installation is run ondiskB, an independent store will be created onB at.pnpm-store. Theprojects would still maintain the benefits of pnpm, but each drive may haveredundant packages.

What doespnpm stand for?

pnpm stands forperformant 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 notdeclared inpackage.json. It is a common mistake caused by flatnode_modules. If this happens, this is an error in the dependency and thedependency should be fixed. That might take time though, so pnpm supportsworkarounds to make the buggy packages work.

Solution 1

In case there are issues, you can use thenode-linker=hoisted setting.This creates a flatnode_modules structure similar to the one created bynpm.

Solution 2

In the following example, a dependency doesnot have theiterall module inits own list of deps.

The easiest solution to resolve missing dependencies of the buggy packages is toadditerall as a dependency to our project'spackage.json.

You can do so, by installing it viapnpm add iterall, and will beautomatically added to your project'spackage.json.

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

Solution 3

One of the solutions is to usehooks for adding the missingdependencies to the package'spackage.json.

An example wasWebpack Dashboard which wasn't working withpnpm. It hassince been resolved such that it works withpnpm now.

It used to throw an error:

Error: Cannot find module 'babel-traverse'
at /node_modules/inspectpack@2.2.3/node_modules/inspectpack/lib/actions/parse

The problem was thatbabel-traverse was used ininspectpack whichwas used bywebpack-dashboard, butbabel-traverse wasn't specified ininspectpack'spackage.json. It still worked withnpm andyarn becausethey create flatnode_modules.

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

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

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


[8]ページ先頭

©2009-2025 Movatter.jp