package.json config ignored
The package.json version of configuring detect_chromedriver_version listed in the readme doesn't work any more:
package.json
{
"dependencies": { "chromedriver": "143.x" },
"config": { "detect_chromedriver_version": true }
}
npm install --foreground-scripts
[email protected] install node install.js Saving to file: /var/folders/_3/1g2w0nys3cl5_0hscz3qrgt00000gn/T/143.0.7499.40/chromedriver/chromedriver-mac-arm64.zip ChromeDriver binary exists. Validating... ChromeDriver is already available at '/var/folders/_3/1g2w0nys3cl5_0hscz3qrgt00000gn/T/143.0.7499.40/chromedriver/chromedriver-mac-arm64/chromedriver'. Copying from /var/folders/_3/1g2w0nys3cl5_0hscz3qrgt00000gn/T/143.0.7499.40/chromedriver/chromedriver-mac-arm64 to target path /[snip]/node_modules/chromedriver/lib/chromedriver Fixing file permissions. Done. ChromeDriver binary available at /[snip]/node_modules/chromedriver/lib/chromedriver/chromedriver added 72 packages, and audited 73 packages in 2s 7 packages are looking for funding run `npm fund` for details found 0 vulnerabilities
Compare that output with using an environment variable for the same purpose:
DETECT_CHROMEDRIVER_VERSION=true npm install --foreground-scripts
[...] Your Chrome version is 143.0.7499.41 Finding Chromedriver version. Chromedriver version is 143.0.7499.40. Compatible ChromeDriver version is 143.0.7499.40 [...]
In the first case, it behaves as if we didn't specify detect_chromedriver_version at all (in this specific example we end up with the same version anyway, but the first run didn't check the installed version and just used its default).
Adding a debug script:
{
"scripts": {"install": "env | grep npm_package"},
"dependencies": { "chromedriver": "143.x" },
"config": { "detect_chromedriver_version": true }
}
npm_package_json=/[snip]/package.json npm_package_config_detect_chromedriver_version=true npm_lifecycle_script=env | grep npm_package
So the environment variable does seem to be getting set correctly by NPM.
This also applies to other config options (e.g. "config": { "chromedriver_version": "LATEST_80" } is ignored).
Node.js version: v24.10.0, v24.11.1 NPM version: 11.6.1, 11.6.2 chromedriver package version: 143.0.0
I ran another test building+installing a stub package and I see that it's an NPM behaviour: it's setting npm_package_* environment variables based on the installed package's package.json, not the installer's package.json.
Presumably this is a recent change in NPM's behaviour (maybe it previously merged them?)
It might be better to load the installer's package.json explicitly (from join(process.env.npm_config_local_prefix, 'package.json')), because presuambly npm_package_* was always intended to be info about the current package, rather than the root.