2

When I run npm install <package>@<version> I am trying to only install one specific package, however, the entire package.json dependencies are installed along with the <package>. Is there any way to prevent all of the other dependency installs and only focus on the specific package?

Based off of the first few responses, it seems like --no-optional seems like the answer, but this is not working for me. On the first ever install with --no-optional, it only install the one package. But then if I run an

npm i
rm -rf node_modules
npm i --no-optional <package>@<version>

it will start installing the entire dependency list again. Try to reproduce with this package.json

{
  "name": "my-app",
  "dependencies": {
    "is-sorted": "^1.0.5",
    "moment": "2.24.0"
  }
}

The --no-optional flag will not work on consecutive runs. Running a npm cache clean --force does not help either

Jeremy
  • 1,717
  • 5
  • 30
  • 49
  • Are you referring to only the optional dependencies? Use `--no-optional` flag. The non-optional dependencies, there is no point in installing a package without its required dependencies. I suppose if you really needed to you could run the install and then remove them from your package and package.json files manually. I wouldn't recommend it. – TheBatman Apr 24 '19 at 18:33
  • I have updated my question to include why `--no-optional` is not working for me – Jeremy Apr 24 '19 at 18:55
  • `npm i` will install missing dependencies. Don't run `npm i` without the `--no-optional` flag – TheBatman Apr 24 '19 at 18:58

2 Answers2

0

--no-optional argument will prevent optional dependencies from being installed.

evilGenius
  • 1,041
  • 1
  • 7
  • 16
0

If you want to avoid the installation of optional dependencies, use --no-optional.

If you, for a specific reason, want to install it without any dependencies, this is currently not possible. It has been requested multiple times, see here:

[Edit] You might also want to check out these threads:

TheOperator
  • 5,936
  • 29
  • 42