DEV Community

Saul Hardman
Saul Hardman

Posted on • Originally published at viewsource.io on

6 1

How to Configure Yarn on Netlify

Netlify Build is a great platform for running static site builds in conjunction with your Git workflow and Headless CMS content updates (via Webhooks). It makes running cloud-based builds of JavaScript Static Site Generators very slick, but it's not without its pitfalls.

Many of the popular generators use Yarn as a package manager which can be configured via Netlify's netlify.toml configuration file, like so:-

# netlify.toml

[build.environment]
  YARN_VERSION = "1.17.3"
  NODE_ENV = "production"
Enter fullscreen mode Exit fullscreen mode

Note: the "Yarn approved" method of specifying the required version is via the yarn policies set-version command.

Running the build step in an environment other than local development had me wondering whether to install packages as dependencies or devDependencies. With the environment variable NODE_ENV set to "production" Yarn will only install dependencies specified in the dependencies section of the package.json file, and not those within devDependencies.

Perhaps NODE_ENV could be set to "production" within the scope of the build command? For example:-

{
  "scripts": {
    "build": "NODE_ENV=production ..."
  }
}
Enter fullscreen mode Exit fullscreen mode

The cleanest solution (in my humble opinion) is to set the --production flag to false, like so:-

# netlify.toml

[build.environment]
  YARN_VERSION = "1.17.3"
  YARN_FLAGS = "--production=false"
  NODE_ENV = "production"
Enter fullscreen mode Exit fullscreen mode

You can find out more about configuring build environment variables within the Netlify documentation.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs