Skip to content

Instantly share code, notes, and snippets.

@akshayjai1
Created October 28, 2022 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akshayjai1/4326c1a2b4b625186527138ac0e5f046 to your computer and use it in GitHub Desktop.
Save akshayjai1/4326c1a2b4b625186527138ac0e5f046 to your computer and use it in GitHub Desktop.
A script that can be added to run before npm start or any other script to enforce a particular npm version
const { exec } = require('child_process');
exec('npm -v', (err, stdout) => {
if (err) throw err;
if (parseInt(stdout) !== 8) {
// NOTE: This can happen if you have a dependency which lists an old version of npm in its own dependencies.
throw new Error(`[ERROR] You need npm version @8 but you have ${stdout}`);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment