npm / npm/cli

[BUG] `.npmrc` created in project root

Open
#5,947 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 9.x
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

When creating a project npm create ... or pnpm create ... I find a .npmrc in the project root.

prefix=/home/<username>/.npm-packages

I already have ~/.npmrc so another should not be necessary, and would be wrong if someone else pulled this project from github.

Expected Behavior

If a global .npmrc already exists, use that. Don't create a new, with identical contents.

If a global .npmrc already exists, but npm create ... need additional options, add those to a local .npmrc, and do some kind of merge, when those options are needed.

Steps To Reproduce

With an existing ~/.npmrc containing prefix= and run npm create svelte my-project should do the trick.

Environment
  • npm: 9.2.0
  • Node.js: 18.12.1
  • OS Name: Slackware64 15.0 (Headless)
  • System Model Name: Linux 5.15.80 SMP PREEMPT Sun Nov 27 13:28:05 CST 2022 x86_64 Intel(R) Xeon(R) CPU E3-1230 v5 @ 3.40GHz GenuineIntel GNU/Linux
  • npm config:
; copy and paste output from `npm config ls` here
$ npm config ls
; "user" config from /home/<user>/.npmrc

prefix = "/home/<user>/.npm-packages" 

; "cli" config from command line options

location = "project" 

; node bin location = /usr/bin/node
; node version = v18.12.1
; npm local prefix = /home/<user>/local/github/svelte.js/vite-sveltekit-template-ts
; npm version = 9.2.0
; cwd = /home/<user>/local/github/svelte.js/vite-sveltekit-template-ts
; HOME = /home/<user>

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

Start by reproducing npm create svelte my-project with a user-level ~/.npmrc containing prefix=, then inspect the npm CLI paths handling project configuration and .npmrc creation. Compare npm config ls before and after; done means an unnecessary project-root .npmrc is not created, while required local options still work without overwriting user configuration.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.