Verify latest release
pnpm version
No response
Which area(s) of pnpm are affected? (leave empty if unsure)
Package manager compatibility
Link to the code that reproduces this issue or a replay of the bug
main...eagarwal-notion:pnpm:eagarwal-pnpm-lifecycle-scripts-env-var
Reproduction steps
Run the test from that commit.
cd pnpm && pnpm test test/install/lifecycleScripts.ts
Basically:
- Create a
pnpm-workspace.yaml with
- At least 1 dependency
- optimisticRepeatInstall set to true.
- A pre-install script which prints the value of
npm_config_user_agent
- Create an up to date lockfile (IE: run
pnpm install --lockfile-only) but don't actually install any dependencies
- Run
pnpm install again
- Check if
npm_config_user_agent is defined/not empty
Running the test locally, the npm_config_user_agent variable is undefined.
● lifecycle script runs with the correct user agent with dependencies (lockfile exists = true)
expect(received).toContain(expected) // indexOf
Expected substring: "pnpm/11.4.0 "
Received string: "Lockfile is up to date, resolution step is skipped
Progress: resolved 1, reused 0, downloaded 0, added 0
Packages: +1
+
Progress: resolved 1, reused 0, downloaded 1, added 1, done·
dependencies:
+ is-positive 1.0.0·
undefined
Done in 469ms using pnpm v11.4.0
"
56 | expect(result.status).toBe(0)
57 | const expectedUserAgentPrefix = `${pnpmPkg.name}/${pnpmPkg.version} `
> 58 | expect(result.stdout.toString()).toContain(expectedUserAgentPrefix)
| ^
59 | })
60 |
61 |
at test/install/lifecycleScripts.ts:58:36
Describe the Bug
We have a preinstall script which reads npm_config_user_agent to determine if its run with pnpm or npm.
If the lockfile already exists but we still need to install dependencies, pnpm doesn't set npm_config_user_agent when running pnpm install. This breaks our preinstall script.
Expected Behavior
npm_config_user_agent is set correctly even if the lockfile exists
Which Node.js version are you using?
24.6.0
Which operating systems have you used?
If your OS is a Linux based, which one it is? (Include the version if relevant)
Debian
Verify latest release
pnpm version
No response
Which area(s) of pnpm are affected? (leave empty if unsure)
Package manager compatibility
Link to the code that reproduces this issue or a replay of the bug
main...eagarwal-notion:pnpm:eagarwal-pnpm-lifecycle-scripts-env-var
Reproduction steps
Run the test from that commit.
cd pnpm && pnpm test test/install/lifecycleScripts.tsBasically:
pnpm-workspace.yamlwithnpm_config_user_agentpnpm install --lockfile-only) but don't actually install any dependenciespnpm installagainnpm_config_user_agentis defined/not emptyRunning the test locally, the
npm_config_user_agentvariable is undefined.Describe the Bug
We have a preinstall script which reads
npm_config_user_agentto determine if its run with pnpm or npm.If the lockfile already exists but we still need to install dependencies, pnpm doesn't set
npm_config_user_agentwhen runningpnpm install. This breaks our preinstall script.Expected Behavior
npm_config_user_agentis set correctly even if the lockfile existsWhich Node.js version are you using?
24.6.0
Which operating systems have you used?
If your OS is a Linux based, which one it is? (Include the version if relevant)
Debian