npm / npm/cli

[BUG] arrays in .npmrc are mangled when set as npm_config_ enironment variables breaking configuration

Open
#5,499 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Release 8.x ws:config
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

With the following in .npmrc on npm@8.19.1

public-hoist-pattern[] = @react-native-community/cli-platform-android*
public-hoist-pattern[] = @react-native-google-signin/google-signin*

When running a script an environment variable public-hoist-pattern gets set to a mangled multiline string

public-hoist-pattern = "\"@react-native-community/cli-platform-android*\\n\\n@react-native-google-signin/google-signin*\""

This env var overrides any parsing of .npmrc and breaks builds because the array got mangled into a multiline string.

Expected Behavior

Npm does not set npm_config_ environment variables (I couldn't find this docmented anywhere) or at least doesn't mangle the information in .npmrc if it does.

Steps To Reproduce
  1. npm install -g npm@8.19.1
  2. add an array to .npmrc
  3. run any script in package.json that outputs env
  4. see the array has been mangled by npm into an undocumented npm_config_ environment variable as a multiline string

Rolling back to npm@7.18.1 fixes the issue as it no longer sets the undocumented environment variables

See related issue on pnpm https://github.com/pnpm/pnpm/issues/5347

Environment
  • npm: 8.19.1
  • Node.js: 16.17.0
  • OS Name: MacOS 12.5.1 arm64
  • System Model Name: Macbook Pro 16 M1Pro 2021
  • npm config:
; "project" config from /Users/imagio/dev/project/.npmrc

public-hoist-pattern = ["@react-native-community/cli-platform-android*","@react-native-google-signin/google-signin*"]

; node bin location = /Users/imagio/.fnm/node-versions/v16.17.0/installation/bin/node
; node version = v16.17.0
; npm local prefix = /Users/imagio/dev/project
; npm version = 8.19.1
; cwd = /Users/imagio/dev/project
; HOME = /Users/imagio

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with npm@8.19.1 using the shown .npmrc array entries and a package.json script that outputs env. Compare the generated npm_config_ environment variable with npm@7.18.1 and verify the array remains intact rather than becoming a mangled multiline string.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.