javascriptnode.jsnpmyarnpkg

Why does yarn install dev dependencies but I just need the builds?


If I use yarn add <package-name>, Yarn will install both dependencies and devDependencies of <package-name>. Is it intended?

I checked the documentation but I couldn't find a way to prevent installing the development dependencies. devDependencies are the dependencies that were used to compile the sources of one package, therefore if I am in a production environment I don't need them.


Solution

  • Since yarn 3 and more recents version (4 at least)

    --production flag doesn't exist anymore. Use this command instead:

    yarn workspaces focus --production
    

    More details here https://yarnpkg.com/cli/workspaces/focus

    Old answer yarn 1 & 2 compatible

    Use --production=true (or simply --production or --prod for short). It is indeed normal behaviour; Yarn assumes you are in a 'development' context unless your NODE_ENV environment variable is set to 'production'.

    Have a look at Yarn's documentation.