1

I just learned that using npm i will not update packages to the version specified in the package.json if they are already installed. Is there a way to force an update for all modules to match the version specified in package.json?

For reference, here is how I'm calling to install from the code currently:

var Proc = child_process.execSync ('npm i', {
        cwd: cwd
      }); 
Austin
  • 347
  • 7
  • 21
  • `npm i will not update packages to the version specified in the package.json`, any source? – lastr2d2 Mar 01 '21 at 06:10
  • @lastr2d2 https://stackoverflow.com/questions/12478679/npm-install-vs-update-whats-the-difference – Austin Mar 01 '21 at 06:12
  • try `npm ci`, it will do a clean install using your package and package-lock.json – coagmano Mar 01 '21 at 06:32
  • @FredStark that gives me the error "npm WARN prepare removing existing node_modules/ before installation" when it's run through code – Austin Mar 02 '21 at 04:59
  • that's not an error – coagmano Mar 02 '21 at 05:00
  • or you could use https://www.npmjs.com/package/libnpm instead of `exec` to call npm functions – coagmano Mar 02 '21 at 05:03
  • Also, you can tell npm to install a specific version in package.json by omitting the default `^` prefix. See docs for version specifiers here: https://docs.npmjs.com/cli/v7/configuring-npm/package-json#dependencies – coagmano Mar 02 '21 at 05:05
  • Using that flag does not seem to matter. npm ci is not deleted node_modules, so it's not installing new ones with the specified version – Austin Mar 02 '21 at 05:30

0 Answers0