Skip to content

[BUG] @npmcli/config package has implicit dependency on node-gyp #8581

@ecraig12345

Description

@ecraig12345

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

Following the instructions from the @npmcli/config readme:

## USAGE
```js
const Config = require('@npmcli/config')
const { shorthands, definitions, flatten } = require('@npmcli/config/lib/definitions')

The second line throws because @npmcli/config/lib/definitions has an implicit dependency on node-gyp.

'node-gyp': new Definition('node-gyp', {
default: require.resolve('node-gyp/bin/node-gyp.js'),

Expected Behavior

The code above shouldn't throw. It preferably also shouldn't require the config package consumer to have node-gyp installed in their project, since there are various possible reasons for wanting to read an npm config where that setting is irrelevant (getting auth info in my case).

Steps To Reproduce

  1. In an empty folder, run npm init -y
  2. npm add -S @npmcli/config
  3. node then paste these lines from the @npmcli/config readme:
    const Config = require('@npmcli/config')
    const { shorthands, definitions, flatten } = require('@npmcli/config/lib/definitions')
  4. Second line above throws an exception because node-gyp isn't found

Environment

The relevant thing here is the @npmcli/config package version, 10.4.0 (latest as of writing). None of the rest of this should matter.

  • npm: 11.6.0
  • Node.js: 22.19.0
  • OS Name: macOS
  • System Model Name: Macbook Pro
  • npm config:
; node bin location = /Users/username/.nvm/versions/node/v22.19.0/bin/node
; node version = v22.19.0
; npm local prefix = /Users/username/repros/npm-repro
; npm version = 11.6.0
; cwd = /Users/username/repros/npm-repro
; HOME = /Users/username

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next steps

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions