Skip to content

[BUG] npm using the wrong package.json file from a parent folder #5216

@krtek4

Description

@krtek4

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 trying to install packages using npm install or seeing the current directory using npm prefix, npm display a parent directory also containing a package.json file.

This seems to only happen with the exact package.json file I use for this project. I wasn't able to create a minimal reproductible folder structure.

Expected Behavior

npm uses the current directory as expected.

Steps To Reproduce

± pwd
/home/gilcrt/Repositories/CCI/cci-packages/projects/cci-utils
± ls -l package.json
-rw-r--r-- 1 gilcrt gilcrt 1.2K Jul 25 17:12 package.json
± npm prefix
/home/gilcrt/Repositories/CCI/cci-packages
± cat package.json

{
  "name": "@cci/utils",
  "version": "3.0.1",
  "description": "Internal package with various helpers that are routinely used in CCI Angular projects",
  "author": "Service Cantonal de l'Informatique, Centre de Compétence Internet, Canton du Valais",
  "license": "UNLICENSED",
  "contributors": [<redacted>],
  "scripts": {
    "typecheck": "tsc -p \"tsconfig.typecheck.json\"",
    "test": "ng test --pass-with-no-tests cci-utils",
    "lint": "ng lint cci-utils",
    "build": "ng build cci-utils",
    "version": "npm run lint && npm run test && ts-node --project ../../tsconfig.node.json ../../scripts/update-version.ts cci-utils && npm run build"
  },
  "publishConfig": {
    "directory": "../../dist/cci-utils",
    "registry": "https://nexus.vs.ch/repository/npm-private/"
  },
  "repository": {
    "type": "git",
    "url": "https://git.vs.ch/cci/packages.git",
    "directory": "projects/cci-utils"
  },
  "peerDependencies": {
    "@angular/common": ">=13.0.0",
    "rxjs": "6.6.7"
  },
  "dependencies": {
    "tslib": "^2.2.0",
    "type-fest": "0.16.0"
  },
  "gitHead": "ed1b5036653a84fd593d1d012c1deb0fb424664b"
}

I don't understand why the prefix isnt the current working directory as it should be.

Environment

; "user" config from /home/gilcrt/.npmrc
cafile = "/usr/local/share/ca-certificates/extra/Etat.Vs.pem"

; "project" config from /home/gilcrt/Repositories/CCI/cci-packages/.npmrc

@cci:registry = "https://nexus.vs.ch/repository/npm-private"
always-auth = true
email = "<redacted>"
strict-ssl = false

; node bin location = /usr/bin/node
; node version = v16.16.0
; npm local prefix = /home/gilcrt/Repositories/CCI/cci-packages
; npm version = 8.11.0
; cwd = /home/gilcrt/Repositories/CCI/cci-packages
; HOME = /home/gilcrt
; Run `npm config ls -l` to show all defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions