Each approach described in this thread failed for me for NPM version 8.15.0
on Debian 11
.
Context
The root cause was never determined, but BROWSER=/usr/bin/chromium npm start
, with or without absolute path, always resulted the default browser (Firefox) being opened. However, BROWSER=none
resulted in no browser being opened -- the expected outcome -- which suggests the variable is acknowledged but is being ignored. Seems likely related to this GitHub issue.
Workaround: BROWSER=node_script.js
Per the documentation, BROWSER
can point to an arbitrary JS script:
...If you need to customize the way the browser is launched, you can specify a node script instead. Any arguments passed to npm start
will also be passed to this script, and the url where your app is served will be the last argument. Your script's file name must have the .js
extension.
Procedure
These were the steps followed to implement the workaround.
1. Create/save a script to disk (chromium.js
):
The following is a valid script for Chromium on Debian Linux:
const { exec } = require("child_process");
const cmd = '/usr/bin/chromium ' +
'--disable-web-security ' +
'--user-data-dir=/tmp/chromium-npm-dev ' +
process.argv[process.argv.length-1]
exec(cmd, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
Notes:
cmd
must be updated to suit relevant needs.
- I found it easiest to save it in the root of the NPM project.
2. Start NPM
BROWSER=chromium.js npm start