-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Following the instructions from the @npmcli/config
readme:
cli/workspaces/config/README.md
Lines 54 to 58 in 5db81c3
## 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
.
cli/workspaces/config/lib/definitions/definitions.js
Lines 1306 to 1307 in 5db81c3
'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
- In an empty folder, run
npm init -y
npm add -S @npmcli/config
node
then paste these lines from the@npmcli/config
readme:const Config = require('@npmcli/config') const { shorthands, definitions, flatten } = require('@npmcli/config/lib/definitions')
- 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