Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid installing optional deps with Yarn

In my yarn.lock file I have only one reference to momentjs:

pikaday@^1.6.0:
  version "1.6.1"
  resolved "https://registry.yarnpkg.com/pikaday/-/pikaday-1.6.1.tgz#b91bcb9b8539cedd8d6d08e4e7465e12095671b0"
  optionalDependencies:
    moment "2.x"

I delete all the node_modulesfolder and the yarn.lock file, and run yarn --ignore-optional but the new yarn.lock generated contains the same lines, and it installs moment in my node_modules so it gets included in my bundle.

I am running on the yarn version 0.27.5.

How can avoid to install this dep marked as optional?

like image 318
ciaoben Avatar asked Jul 01 '26 21:07

ciaoben


1 Answers

Turns out Yarn indeed lists all optional dependencies at yarn.lock. However, when --ignore-optional flag is specified those modules aren't installed into node_modules/.

like image 92
LazyCat01 Avatar answered Jul 04 '26 10:07

LazyCat01