Passa al contenuto principale
Versione: 9.x

Settings (.npmrc)

pnpm gets its configuration from the command line, environment variables, and .npmrc files.

The pnpm config command can be used to update and edit the contents of the user and global .npmrc files.

I quattro file rilevanti sono:

  • per-project configuration file (/path/to/my/project/.npmrc)
  • per-workspace configuration file (the directory that contains the pnpm-workspace.yaml file)
  • per-user configuration file (~/.npmrc)
  • global configuration file (/etc/npmrc)

All .npmrc files are an INI-formatted list of key = value parameters.

Values in the .npmrc files may contain env variables using the ${NAME} syntax. The env variables may also be specified with default values. Using ${NAME-fallback} will return fallback if NAME isn't set. ${NAME:-fallback} will return fallback if NAME isn't set, or is an empty string.

Impostazioni di inserimento delle dipendenze

hoist

  • Default: true
  • Type: boolean

When true, all dependencies are hoisted to node_modules/.pnpm/node_modules. This makes unlisted dependencies accessible to all packages inside node_modules.

hoist-workspace-packages

  • Default: true
  • Type: boolean

When true, packages from the workspaces are symlinked to either <workspace_root>/node_modules/.pnpm/node_modules or to <workspace_root>/node_modules depending on other hoisting settings (hoist-pattern and public-hoist-pattern).

hoist-pattern

  • Default: ['*']
  • Type: string[]

Tells pnpm which packages should be hoisted to node_modules/.pnpm/node_modules. Per impostazione predefinita, tutti i pacchetti sono installati - tuttavia, se sai che solo alcuni pacchetti difettosi hanno dipendenze fantasma, è possibile utilizzare questa opzione per installare esclusivamente le dipendenze fantasma (raccomandato).

Ad esempio:

hoist-pattern[]=*eslint*
hoist-pattern[]=*babel*

You may also exclude patterns from hoisting using !.

Ad esempio:

hoist-pattern[]=*types*
hoist-pattern[]=!@types/react

public-hoist-pattern

  • Default: ['*eslint*', '*prettier*']
  • Type: string[]

Unlike hoist-pattern, which hoists dependencies to a hidden modules directory inside the virtual store, public-hoist-pattern hoists dependencies matching the pattern to the root modules directory. Installare nella cartella radice dei moduli significa che il codice dell'applicazione avrà accesso alle dipendenze fantasma, anche se modificano la strategia di risoluzione in modo improprio.

Questa impostazione è utile quando si ha a che fare con alcuni strumenti collegabili difettosi che non risolvere correttamente le dipendenze.

Ad esempio:

public-hoist-pattern[]=*plugin*

Note: Setting shamefully-hoist to true is the same as setting public-hoist-pattern to *.

You may also exclude patterns from hoisting using !.

Ad esempio:

public-hoist-pattern[]=*types*
public-hoist-pattern[]=!@types/react

shamefully-hoist

  • Default: false
  • Type: Boolean

By default, pnpm creates a semistrict node_modules, meaning dependencies have access to undeclared dependencies but modules outside of node_modules do not. Con questo layout, la maggior parte dei pacchetti nell'ecosistema funzionano senza problemi. However, if some tooling only works when the hoisted dependencies are in the root of node_modules, you can set this to true to hoist them for you.

Impostazioni Node-Modules

modules-dir

  • Default: node_modules
  • Type: path

The directory in which dependencies will be installed (instead of node_modules).

node-linker

  • Default: isolated
  • Type: isolated, hoisted, pnp

Definisce quale linker dovrebbe essere usato per installare i pacchetti Node.

  • isolated - dependencies are symlinked from a virtual store at node_modules/.pnpm.
  • hoisted - a flat node_modules without symlinks is created. Same as the node_modules created by npm or Yarn Classic. Una delle librerie di Yarn viene utilizzata per l'hoisting, quando viene utilizzata questa impostazione. Motivi legittimi per utilizzare questa impostazione:
    1. I tuoi strumenti non funzionano bene con i collegamenti simbolici. A React Native project will most probably only work if you use a hoisted node_modules.
    2. Il tuo progetto viene distribuito a un provider di hosting senza server. Alcuni provider senza server (ad esempio, AWS Lambda) non supportano i collegamenti simbolici. Una soluzione alternativa a questo problema consiste nel raggruppare l'applicazione prima della distribuzione.
    3. If you want to publish your package with "bundledDependencies".
    4. If you are running Node.js with the --preserve-symlinks flag.
  • pnp - no node_modules. Plug'n'Play is an innovative strategy for Node that is used by Yarn Berry. It is recommended to also set symlink setting to false when using pnp as your linker.
  • Default: true
  • Type: Boolean

When symlink is set to false, pnpm creates a virtual store directory without any symlinks. It is a useful setting together with node-linker=pnp.

enable-modules-dir

  • Default: true
  • Type: Boolean

When false, pnpm will not write any files to the modules directory (node_modules). Questo è utile quando la cartella dei moduli è montata con filesystem nello spazio utente (FUSE). There is an experimental CLI that allows you to mount a modules directory with FUSE: @pnpm/mount-modules.

virtual-store-dir

  • Default: node_modules/.pnpm
  • Types: path

La cartella con i collegamenti all'archivio. Tutte le dipendenze dirette e indirette del progetto sono collegate in questa cartella.

Questa è un'impostazione utile che può risolvere problemi con percorsi lunghi su Windows. If you have some dependencies with very long paths, you can select a virtual store in the root of your drive (for instance C:\my-project-store).

Or you can set the virtual store to .pnpm and add it to .gitignore. Questo renderà gli stacktrace più puliti poiché i percorsi delle dipendenze saranno di una cartella più in alto.

NOTE: the virtual store cannot be shared between several projects. Ogni progetto dovrebbe avere un proprio archivio virtuale (tranne negli spazi di lavoro dove è condivisa la radice).

virtual-store-dir-max-length

Added in: v9.1.0

  • Default: 120
  • Types: number

Sets the maximum allowed length of directory names inside the virtual store directory (node_modules/.pnpm). You may set this to a lower number if you encounter long path issues on Windows.

package-import-method

  • Default: auto
  • Type: auto, hardlink, copy, clone, clone-or-copy

Controls the way packages are imported from the store (if you want to disable symlinks inside node_modules, then you need to change the node-linker setting, not this one).

  • auto - try to clone packages from the store. Se la clonazione non è supportata collega i pacchetti dall'archivio. Se né la clonazione né il collegamento è possibile, esegue la copia
  • hardlink - hard link packages from the store
  • clone-or-copy - try to clone packages from the store. Se la clonazione non è supportata, allora torna alla copia
  • copy - copy packages from the store
  • clone - clone (AKA copy-on-write or reference link) packages from the store

La clonazione è il modo migliore per scrivere pacchetti in node_modules. È il modo più veloce e più sicuro. Quando viene utilizzata la clonazione, puoi modificare i file nei tuoi node_modules e non verranno modificati nell'archivio centrale indirizzabile al contenuto.

Sfortunatamente, non tutti i file system supportano la clonazione. Si consiglia di utilizzare un file system copy-on-write (CoW) (ad esempio, Btrfs invece di Ext4 su Linux) per la migliore esperienza con pnpm.

modules-cache-max-age

  • Default: 10080 (7 days in minutes)
  • Type: number

Il tempo in minuti dopo il quale i pacchetti orfani dalla cartella dei moduli devono essere rimossi. pnpm mantiene una cache dei pacchetti nella cartella dei moduli. Questa velocità di installazione aumenta quando si cambia ramo o si retrocedono delle dipendenze.

dlx-cache-max-age

  • Default: 1440 (1 day in minutes)
  • Type: number

The time in minutes after which dlx cache expires. After executing a dlx command, pnpm keeps a cache that omits the installation step for subsequent calls to the same dlx command.

Store Settings

store-dir

  • Predefinito:
    • If the $PNPM_HOME env variable is set, then $PNPM_HOME/store
    • If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm/store
    • On Windows: ~/AppData/Local/pnpm/store
    • On macOS: ~/Library/pnpm/store
    • On Linux: ~/.local/share/pnpm/store
  • Type: path

La posizione in cui tutti i pacchetti vengono salvati sul disco.

L'archivio dovrebbe essere sempre sullo stesso disco su cui sta avvenendo l'installazione, quindi ci sarà un archivio per disco. Se è presente una directory home sul disco corrente, l'archivio viene creato al suo interno. Se non c'è nessuna home sul disco, allora l'archivio viene creato alla radice del filesystem. For example, if installation is happening on a filesystem mounted at /mnt, then the store will be created at /mnt/.pnpm-store. Lo stesso vale per i sistemi Windows.

È possibile impostare un archivio da un disco diverso, ma in tal caso pnpm copierà i pacchetti dallo store invece di collegarli, poiché i collegamenti fisici sono possibili solo sullo stesso filesystem.

verify-store-integrity

  • Default: true
  • Type: Boolean

By default, if a file in the store has been modified, the content of this file is checked before linking it to a project's node_modules. If verify-store-integrity is set to false, files in the content-addressable store will not be checked during installation.

use-running-store-server

danger

Deprecated feature

  • Default: false
  • Type: Boolean

Consente l'installazione solo con un server di archiviazione. Se nessun server di archiviazione è in esecuzione, l'installazione fallirà.

strict-store-pkg-content-check

Added in: v9.4.0

  • Default: true
  • Type: Boolean

Some registries allow the exact same content to be published under different package names and/or versions. This breaks the validity checks of packages in the store. To avoid errors when verifying the names and versions of such packages in the store, you may set the strict-store-pkg-content-check setting to false.

Impostazioni file di blocco

lockfile

  • Default: true
  • Type: Boolean

When set to false, pnpm won't read or generate a pnpm-lock.yaml file.

prefer-frozen-lockfile

  • Default: true
  • Type: Boolean

When set to true and the available pnpm-lock.yaml satisfies the package.json dependencies directive, a headless installation is performed. A headless installation skips all dependency resolution as it does not need to modify the lockfile.

lockfile-include-tarball-url

  • Default: false
  • Type: Boolean

Add the full URL to the package's tarball to every entry in pnpm-lock.yaml.

git-branch-lockfile

  • Default: false
  • Type: Boolean

When set to true, the generated lockfile name after installation will be named based on the current branch name to completely avoid merge conflicts. For example, if the current branch name is feature-foo, the corresponding lockfile name will be pnpm-lock.feature-foo.yaml instead of pnpm-lock.yaml. It is typically used in conjunction with the command line argument --merge-git-branch-lockfiles or by setting merge-git-branch-lockfiles-branch-pattern in the .npmrc file.

merge-git-branch-lockfiles-branch-pattern

  • Default: null
  • Type: Array or null

This configuration matches the current branch name to determine whether to merge all git branch lockfile files. By default, you need to manually pass the --merge-git-branch-lockfiles command line parameter. This configuration allows this process to be automatically completed.

Ad esempio:

merge-git-branch-lockfiles-branch-pattern[]=main
merge-git-branch-lockfiles-branch-pattern[]=release*

You may also exclude patterns using !.

peers-suffix-max-length

Added in: v9.3.0

  • Default: 1000
  • Type: number

Max length of the peer IDs suffix added to dependency keys in the lockfile. If the suffix is longer, it is replaced with a hash.

Registry & Authentication Settings

registry

The base URL of the npm package registry (trailing slash included).

&lt;scope>:registry

The npm registry that should be used for packages of the specified scope. For example, setting @babel:registry=https://example.com/packages/npm/ will enforce that when you use pnpm add @babel/core, or any @babel scoped package, the package will be fetched from https://example.com/packages/npm instead of the default registry.

&lt;URL&gt;:_authToken

Define the authentication bearer token to use when accessing the specified registry. Ad esempio:

//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 

You may also use an environment variable. Ad esempio:

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

Or you may just use an environment variable directly, without changing .npmrc at all:

npm_config_//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 

&lt;URL&gt;:tokenHelper

A token helper is an executable which outputs an auth token. This can be used in situations where the authToken is not a constant value but is something that refreshes regularly, where a script or other tool can use an existing refresh token to obtain a new access token.

The configuration for the path to the helper must be an absolute path, with no arguments. In order to be secure, it is only permitted to set this value in the user .npmrc. Otherwise a project could place a value in a project's local .npmrc and run arbitrary executables.

Setting a token helper for the default registry:

tokenHelper=/home/ivan/token-generator

Setting a token helper for the specified registry:

//registry.corp.com:tokenHelper=/home/ivan/token-generator

Impostazioni richiesta

ca

  • Default: The npm CA certificate
  • Type: String, Array or null

Il certificato di firma dell'autorità di certificazione considerato attendibile per le connessioni SSL al registro. I valori devono essere in formato PEM (ovvero "X.509 codificato in base-64 (.CER)"). Ad esempio:

ca="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"

Imposta a null per consentire solo ai registrar noti o un certificato CA specifico di considerare attendibile solo quella specifica autorità di firma.

È possibile considerare attendibili più CA specificando una serie di certificati:

ca[]="..."
ca[]="..."

See also the strict-ssl config.

cafile

  • Default: null
  • Type: path

Un percorso a un file contenente una o più autorità di certificazione che firmano certificati. Similar to the ca setting, but allows for multiple CAs, as well as for the CA information to be stored in a file instead of being specified via CLI.

&lt;URL&gt;:cafile

Define the path to a Certificate Authority file to use when accessing the specified registry. Ad esempio:

//registry.npmjs.org/:keyfile=client-cert.pem

cert

  • Default: null
  • Type: String

Un certificato client da passare quando si accede al registro. I valori devono essere in formato PEM (ovvero "X.509 codificato in base-64 (.CER)"). Ad esempio:

cert="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"

It is not the path to a certificate file.

&lt;URL&gt;:certfile

Define the path to a certificate file to use when accessing the specified registry. Ad esempio:

//registry.npmjs.org/:certfile=server-cert.pem

key

  • Default: null
  • Type: String

Una chiave client da passare quando si accede al registro. I valori devono essere in formato PEM (ovvero "X.509 codificato in base-64 (.CER)"). Ad esempio:

key="-----BEGIN PRIVATE KEY-----\nXXXX\nXXXX\n-----END PRIVATE KEY-----"

It is not the path to a key file (and there is no keyfile option).

Questa impostazione contiene informazioni sensibili. Don't write it to a local .npmrc file committed to the repository.

&lt;URL&gt;:keyfile

Define the path to a client key file to use when accessing the specified registry. Ad esempio:

//registry.npmjs.org/:keyfile=server-key.pem

git-shallow-hosts

  • Default: ['github.com', 'gist.github.com', 'gitlab.com', 'bitbucket.com', 'bitbucket.org']
  • Type: string[]

Durante il recupero delle dipendenze che sono repository Git, se l'host è elencato in questa impostazione, pnpm utilizzerà la clonazione superficiale per recuperare solo il commit necessario, non tutta la cronologia.

https-proxy

  • Default: null
  • Type: url

Un proxy da utilizzare per le richieste HTTPS in uscita. If the HTTPS_PROXY, https_proxy, HTTP_PROXY or http_proxy environment variables are set, their values will be used instead.

If your proxy URL contains a username and password, make sure to URL-encode them. Ad esempio:

https-proxy=https://use%21r:pas%2As@my.proxy:1234/foo

Do not encode the colon (:) between the username and password.

http-proxy

proxy

  • Default: null
  • Type: url

Un proxy da utilizzare per le richieste http in uscita. Se le variabili di ambiente HTTP_PROXY o http_proxy sono impostate, le impostazioni del proxy saranno onorate dalla libreria di richiesta sottostante.

local-address

  • Default: undefined
  • Type: IP Address

L'indirizzo IP dell'interfaccia locale da utilizzare quando si effettuano connessioni al registro npm.

maxsockets

  • Default: network-concurrency x 3
  • Type: Number

Il numero massimo di connessioni da utilizzare per origine (combinazione protocollo/host/porta).

noproxy

  • Default: null
  • Type: String

Una stringa di estensioni di dominio separate da virgole per le quali non dovrebbe essere utilizzato un proxy.

strict-ssl

  • Default: true
  • Type: Boolean

Se eseguire o meno la convalida della chiave SSL quando si effettuano richieste al registro tramite HTTPS.

See also the ca option.

network-concurrency

  • Default: 16
  • Type: Number

Controlla il numero massimo di richieste HTTP(S) da elaborare contemporaneamente.

fetch-retries

  • Default: 2
  • Type: Number

Quante volte riprovare se pnpm non riesce a recuperare dal registro.

fetch-retry-factor

  • Default: 10
  • Type: Number

Il fattore esponenziale per i tentativi di backoff.

fetch-retry-mintimeout

  • Default: 10000 (10 seconds)
  • Type: Number

Il timeout minimo (di base) per ritentare le richieste.

fetch-retry-maxtimeout

  • Default: 60000 (1 minute)
  • Type: Number

Il timeout di fallback massimo per garantire che il fattore di ripetizione non esegua richieste troppo lunghe.

fetch-timeout

  • Default: 60000 (1 minute)
  • Type: Number

Il tempo massimo di attesa per il completamento delle richieste HTTP.

Impostazioni dipendenze peer

auto-install-peers

  • Default: true
  • Type: Boolean

When true, any missing non-optional peer dependencies are automatically installed.

Version Conflicts

If there are conflicting version requirements for a peer dependency from different packages, pnpm will not install any version of the conflicting peer dependency automatically. Instead, a warning is printed. For example, if one dependency requires react@^16.0.0 and another requires react@^17.0.0, these requirements conflict, and no automatic installation will occur.

Conflict Resolution

In case of a version conflict, you'll need to evaluate which version of the peer dependency to install yourself, or update the dependencies to align their peer dependency requirements.

dedupe-peer-dependents

  • Default: true
  • Type: Boolean

When this setting is set to true, packages with peer dependencies will be deduplicated after peers resolution.

For instance, let's say we have a workspace with two projects and both of them have webpack in their dependencies. webpack has esbuild in its optional peer dependencies, and one of the projects has esbuild in its dependencies. In this case, pnpm will link two instances of webpack to the node_modules/.pnpm directory: one with esbuild and another one without it:

node_modules
.pnpm
webpack@1.0.0_esbuild@1.0.0
webpack@1.0.0
project1
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0/node_modules/webpack
project2
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
esbuild

This makes sense because webpack is used in two projects, and one of the projects doesn't have esbuild, so the two projects cannot share the same instance of webpack. However, this is not what most developers expect, especially since in a hoisted node_modules, there would only be one instance of webpack. Therefore, you may now use the dedupe-peer-dependents setting to deduplicate webpack when it has no conflicting peer dependencies (explanation at the end). In this case, if we set dedupe-peer-dependents to true, both projects will use the same webpack instance, which is the one that has esbuild resolved:

node_modules
.pnpm
webpack@1.0.0_esbuild@1.0.0
project1
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
project2
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
esbuild

What are conflicting peer dependencies? By conflicting peer dependencies we mean a scenario like the following one:

node_modules
.pnpm
webpack@1.0.0_react@16.0.0_esbuild@1.0.0
webpack@1.0.0_react@17.0.0
project1
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0/node_modules/webpack
react (v17)
project2
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
esbuild
react (v16)

In this case, we cannot dedupe webpack as webpack has react in its peer dependencies and react is resolved from two different versions in the context of the two projects.

strict-peer-dependencies

  • Default: false
  • Type: Boolean

Se abilitato, i comandi falliranno se c'è una dipendenza peer mancante o non valida nell'albero.

resolve-peers-from-workspace-root

  • Default: true
  • Type: Boolean

Se abilitate, le dipendenze del progetto root dell'area di lavoro vengono utilizzate per risolvere le dipendenze peer di qualsiasi progetto nell'area di lavoro. Si tratta di una funzione utile in quanto è possibile installare le tue dipendenze peer solo nella root dello spazio di lavoro e puoi essere sicuro che tutti i progetti nello spazio di lavoro utilizzano le stesse versioni delle dipendenze peer.

Impostazioni CLI

[no-]color

  • Default: auto
  • Type: auto, always, never

Controlla i colori nell'output.

  • auto - output uses colors when the standard output is a terminal or TTY.
  • always - ignore the difference between terminals and pipes. You’ll rarely want this; in most scenarios, if you want color codes in your redirected output, you can instead pass a --color flag to the pnpm command to force it to use color codes. L'impostazione predefinita è quasi sempre quella che vorrai.
  • never - turns off colors. This is the setting used by --no-color.

loglevel

  • Default: info
  • Type: debug, info, warn, error

Verranno visualizzati tutti i registri pari o superiori al livello indicato. You can instead pass --silent to turn off all output logs.

use-beta-cli

  • Default: false
  • Type: Boolean

Opzione sperimentale che abilita le funzionalità beta della CLI. Ciò significa che è possibile ottenere alcune modifiche alla funzionalità CLI che possono essere modifiche non retrocompatibili, o potenzialmente bug.

recursive-install

  • Default: true
  • Type: Boolean

If this is enabled, the primary behaviour of pnpm install becomes that of pnpm install -r, meaning the install is performed on all workspace or subdirectory packages.

Else, pnpm install will exclusively build the package in the current directory.

engine-strict

  • Default: false
  • Type: Boolean

Se è abilitato, pnpm non installerà alcun pacchetto che affermi di non essere compatibile con la versione corrente di Node.

Regardless of this configuration, installation will always fail if a project (not a dependency) specifies an incompatible version in its engines field.

npm-path

  • Type: path

La posizione del file binario npm che pnpm usa per alcune azioni, come la pubblicazione.

package-manager-strict

  • Default: true
  • Type: Boolean

If this setting is disabled, pnpm will not fail if a different package manager is specified in the packageManager field of package.json. When enabled, only the package name is checked (since pnpm v9.2.0), so you can still run any version of pnpm regardless of the version specified in the packageManager field.

Alternatively, you can disable this setting by setting the COREPACK_ENABLE_STRICT environment variable to 0.

package-manager-strict-version

Added in: v9.2.0

  • Default: false
  • Type: Boolean

When enabled, pnpm will fail if its version doesn't exactly match the version specified in the packageManager field of package.json.

manage-package-manager-versions

Added in: v9.7.0

  • Default: false
  • Type: Boolean

When enabled, pnpm will automatically download and run the version of pnpm specified in the packageManager field of package.json. This is the same field used by Corepack. Esempio:

{
"packageManager": "pnpm@9.3.0"
}

Impostazioni di compilazione

ignore-scripts

  • Default: false
  • Type: Boolean

Do not execute any scripts defined in the project package.json and its dependencies.

note

This flag does not prevent the execution of .pnpmfile.cjs

ignore-dep-scripts

  • Default: false
  • Type: Boolean

Non eseguire alcuno script dei pacchetti installati. Gli script dei progetti vengono eseguiti.

child-concurrency

  • Default: 5
  • Type: Number

Il numero massimo di processi figlio da allocare contemporaneamente per creare node_modules.

side-effects-cache

  • Default: true
  • Type: Boolean

Utilizza e memorizza i risultati degli hook (pre/post)-installazione.

side-effects-cache-readonly

  • Default: false
  • Type: Boolean

Usa solo la cache degli effetti collaterali se presente, non crearla per nuovi pacchetti.

unsafe-perm

  • Default: false IF running as root, ELSE true
  • Type: Boolean

Imposta a true per abilitare la commutazione UID/GID durante l'esecuzione di script di pacchetto. Se impostato esplicitamente su false, l'installazione come utente non root avrà esito negativo.

node-options

  • Default: NULL
  • Type: String

Options to pass through to Node.js via the NODE_OPTIONS environment variable. This does not impact how pnpm itself is executed but it does impact how lifecycle scripts are called.

Impostazioni di Node.js

use-node-version

  • Default: undefined
  • Type: semver

Specifica quale versione esatta di Node.js deve essere utilizzata per il runtime del progetto. pnpm will automatically install the specified version of Node.js and use it for running pnpm run commands or the pnpm node command.

This may be used instead of .nvmrc and nvm. Instead of the following .nvmrc file:

16.16.0

Use this .npmrc file:

use-node-version=16.16.0

This setting works only in a .npmrc file that is in the root of your workspace. If you need to specify a custom Node.js for a project in the workspace, use the pnpm.executionEnv.nodeVersion field of package.json instead.

node-version

  • Default: the value returned by node -v, without the v prefix
  • Type: semver

The Node.js version to use when checking a package's engines setting.

If you want to prevent contributors of your project from adding new incompatible dependencies, use node-version and engine-strict in a .npmrc file at the root of the project:

node-version=12.22.0
engine-strict=true

In questo modo, anche se qualcuno sta usando Node.js v16, non sarà in grado di installare una nuova dipendenza che non supporta Node.js v12.22.0.

node-mirror:&lt;releaseDir>

  • Default: https://nodejs.org/download/<releaseDir>/
  • Type: URL

Imposta l'URL di base per il download di Node.js. The <releaseDir> portion of this setting can be any directory from https://nodejs.org/download: release, rc, nightly, v8-canary, etc.

Ecco come configurare pnpm per scaricare Node.js dal mirror Node.js in Cina:

node-mirror:release=https://npmmirror.com/mirrors/node/
node-mirror:rc=https://npmmirror.com/mirrors/node-rc/
node-mirror:nightly=https://npmmirror.com/mirrors/node-nightly/

Impostazioni dell'area di lavoro

  • Default: false
  • Type: true, false, deep

If this is enabled, locally available packages are linked to node_modules instead of being downloaded from the registry. This is very convenient in a monorepo. If you need local packages to also be linked to subdependencies, you can use the deep setting.

Else, packages are downloaded and installed from the registry. However, workspace packages can still be linked by using the workspace: range protocol.

prefer-workspace-packages

  • Default: false
  • Type: Boolean

If this is enabled, local packages from the workspace are preferred over packages from the registry, even if there is a newer version of the package in the registry.

This setting is only useful if the workspace doesn't use save-workspace-protocol.

shared-workspace-lockfile

  • Default: true
  • Type: Boolean

If this is enabled, pnpm creates a single pnpm-lock.yaml file in the root of the workspace. This also means that all dependencies of workspace packages will be in a single node_modules (and get symlinked to their package node_modules folder for Node's module resolution).

Advantages of this option:

  • ogni dipendenza è un elemento singolo
  • installazioni più veloci in un monorepo
  • meno modifiche nelle revisioni del codice poiché sono tutte in un unico file
note

Even though all the dependencies will be hard linked into the root node_modules, packages will have access only to those dependencies that are declared in their package.json, so pnpm's strictness is preserved. This is a result of the aforementioned symbolic linking.

save-workspace-protocol

  • Default: rolling
  • Type: true, false, rolling

This setting controls how dependencies that are linked from the workspace are added to package.json.

If foo@1.0.0 is in the workspace and you run pnpm add foo in another project of the workspace, below is how foo will be added to the dependencies field. The save-prefix setting also influences how the spec is created.

save-workspace-protocolsave-prefixspec
false''1.0.0
false'~'~1.0.0
false'^'^1.0.0
true''workspace:1.0.0
true'~'workspace:~1.0.0
true'^'workspace:^1.0.0
rolling''workspace:*
rolling'~'workspace:~
rolling'^'workspace:^

include-workspace-root

  • Default: false
  • Type: Boolean

Quando si eseguono comandi ricorsivamente in un'area di lavoro, eseguili anche nel progetto dell'area di lavoro radice.

ignore-workspace-cycles

  • Default: false
  • Type: Boolean

When set to true, no workspace cycle warnings will be printed.

disallow-workspace-cycles

  • Default: false
  • Type: Boolean

When set to true, installation will fail if the workspace has cycles.

Altre opzioni

save-prefix

  • Default: '^'
  • Type: '^', '~', ''

Configure how versions of packages installed to a package.json file get prefixed.

For example, if a package has version 1.2.3, by default its version is set to ^1.2.3 which allows minor upgrades for that package, but after pnpm config set save-prefix='~' it would be set to ~1.2.3 which only allows patch upgrades.

Questa impostazione viene ignorata quando il pacchetto aggiunto ha un intervallo specificato. For instance, pnpm add foo@2 will set the version of foo in package.json to 2, regardless of the value of save-prefix.

tag

  • Default: latest
  • Type: String

If you pnpm add a package and you don't provide a specific version, then it will install the package at the version registered under the tag from this setting.

This also sets the tag that is added to the package@version specified by the pnpm tag command if no explicit tag is given.

global-dir

  • Predefinito:
    • If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm/global
    • On Windows: ~/AppData/Local/pnpm/global
    • On macOS: ~/Library/pnpm/global
    • On Linux: ~/.local/share/pnpm/global
  • Type: path

Specifica una cartella personalizzata per archiviare i pacchetti globali.

global-bin-dir

  • Predefinito:
    • If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm
    • On Windows: ~/AppData/Local/pnpm
    • On macOS: ~/Library/pnpm
    • On Linux: ~/.local/share/pnpm
  • Type: path

Consente di impostare la cartella di destinazione per i file bin dei pacchetti installati globalmente.

state-dir

  • Predefinito:
    • If the $XDG_STATE_HOME env variable is set, then $XDG_STATE_HOME/pnpm
    • On Windows: ~/AppData/Local/pnpm-state
    • On macOS: ~/.pnpm-state
    • On Linux: ~/.local/state/pnpm
  • Type: path

The directory where pnpm creates the pnpm-state.json file that is currently used only by the update checker.

cache-dir

  • Predefinito:
    • If the $XDG_CACHE_HOME env variable is set, then $XDG_CACHE_HOME/pnpm
    • On Windows: ~/AppData/Local/pnpm-cache
    • On macOS: ~/Library/Caches/pnpm
    • On Linux: ~/.cache/pnpm
  • Type: path

The location of the cache (package metadata and dlx).

use-stderr

  • Default: false
  • Type: Boolean

Se true, tutto l'output viene scritto su stderr.

update-notifier

  • Default: true
  • Type: Boolean

Set to false to suppress the update notification when using an older version of pnpm than the latest.

prefer-symlinked-executables

  • Default: true, when node-linker is set to hoisted and the system is POSIX
  • Type: Boolean

Create symlinks to executables in node_modules/.bin instead of command shims. Questa impostazione viene ignorata su Windows, dove funzionano solo i comandi shim.

ignore-compatibility-db

  • Default: false
  • Type: Boolean

Durante l'installazione le dipendenze di alcuni pacchetti vengono automaticamente corrette. If you want to disable this, set this config to false.

The patches are applied from Yarn's @yarnpkg/extensions package.

resolution-mode

  • Default: highest (was lowest-direct from v8.0.0 to v8.6.12)
  • Type: highest, time-based, lowest-direct

When resolution-mode is set to time-based, dependencies will be resolved the following way:

  1. Le dipendenze dirette verranno risolte alle versioni più basse. So if there is foo@^1.1.0 in the dependencies, then 1.1.0 will be installed.
  2. Le sottodipendenze verranno risolte dalle versioni pubblicate prima della pubblicazione dell'ultima dipendenza diretta.

Con questa modalità di risoluzione, le installazioni con cache calda sono più veloci. Riduce inoltre la possibilità di dirottamento delle sottodipendenze poiché le sottodipendenze verranno aggiornate solo se vengono aggiornate le dipendenze dirette.

This resolution mode works only with npm's full metadata. Quindi è più lento in alcuni scenari. However, if you use Verdaccio v5.15.1 or newer, you may set the registry-supports-time-field setting to true, and it will be really fast.

When resolution-mode is set to lowest-direct, direct dependencies will be resolved to their lowest versions.

registry-supports-time-field

  • Default: false
  • Type: Boolean

Set this to true if the registry that you are using returns the "time" field in the abbreviated metadata. As of now, only Verdaccio from v5.15.1 supports this.

extend-node-path

  • Default: true
  • Type: Boolean

When false, the NODE_PATH environment variable is not set in the command shims.

deploy-all-files

  • Default: false
  • Type: Boolean

When deploying a package or installing a local package, all files of the package are copied. By default, if the package has a "files" field in the package.json, then only the listed files and directories are copied.

dedupe-direct-deps

  • Default: false
  • Type: Boolean

When set to true, dependencies that are already symlinked to the root node_modules directory of the workspace will not be symlinked to subproject node_modules directories.

dedupe-injected-deps

  • Default: true
  • Type: Boolean

When this setting is enabled, dependencies that are injected will be symlinked from the workspace whenever possible. If the dependent project and the injected dependency reference the same peer dependencies, then it is not necessary to physically copy the injected dependency into the dependent's node_modules; a symlink is sufficient.