<p>So we are in the process of moving from yarn 1.x to yarn 2 (yarn 3.1.1) and I'm getting a little confused on how to configure yarn in my CI/CD config. As of right now our pipeline does the following to deploy to our kubernetes cluster:</p>
<p>On branch PR:</p>
<ol>
<li><p>Obtain branch repo in gitlab runner</p>
</li>
<li><p>Lint</p>
</li>
<li><p>Run jest</p>
</li>
<li><p>Build with environment variables, dependencies, and devdependencies</p>
</li>
<li><p>Publish image to container registry with tag <code>test</code></p>
<p>a. If success, allow merge to main</p>
</li>
<li><p>Kubernetes watches for updates to test and deploys a test pod to cluster</p>
</li>
</ol>
<p>On merge to main:</p>
<ol>
<li>Obtain main repo in gitlab runner</li>
<li>Lint</li>
<li>Run jest</li>
<li>Build with environment variables and dependencies</li>
<li>Publish image to container registry with tag <code>latest</code></li>
<li>Kubernetes watches for updates to latest and deploys a staging pod to cluster</li>
</ol>
<p>(NOTE: For full-blown production releases we will be using the release feature to manually deploy releases to the production server)</p>
<p>The issue is that we are using yarn 2 with zero installs and in the past we have been able prevent the production environment from using any dev dependencies by running <code>yarn install --production</code>. In yarn 2 this command is deprecated.</p>
<p>Is there any ideal solution to prevent dev dependencies from being installed on production? I've seen some posts mention using workspaces but that seems to be more tailored towards mono-repos where there are more than one application.</p>
<p>Thanks in advance for any help!</p>

liamlows
<p>I had the same question and came to the same conclusion as you. I could not find an easy way to perform a production build on yarn 2. Yarn Workspaces comes closest but I did find the paragraph below in the documentation:</p>
<blockquote>
<p>Note that this command is only very moderately useful when using zero-installs, since the cache will contain all the packages anyway - meaning that the only difference between a full install and a focused install would just be a few extra lines in the .pnp.cjs file, at the cost of introducing an extra complexity.</p>
</blockquote>
<p>From: <a href="https://yarnpkg.com/cli/workspaces/focus#options-production" rel="nofollow noreferrer">https://yarnpkg.com/cli/workspaces/focus#options-production</a></p>
<p>Does that mean that there essentially is no production install? It would be nice if that was officially addressed somewhere but this was the closest I could find.</p>
<p>Personally, I am using NextJS and upgraded my project to Yarn 2. The features of Yarn 2 seem to work (no node_modules folder) but I can still use <code>yarn build</code> from NextJS to create a production build with output in the <code>.next</code> folder.</p>
