YARN_FLAGS env variable being ignored

My site name is https://homeclu-demo.netlify.app/

I have a problem where setting the “YARN_FLAGS” environment variable is not being used by the yarn install command as mentioned in the docs

I’ve tried setting it via the UI first, and via a netlify.toml file afterwards, of which neither worked.

I’m specifying the environment variable in netlify.toml as follows:

[build.environment]
    YARN_FLAGS = "--ignore-optional --registry https://npm.greensock.com"

The build log can be found here Paste.ee

As you can see, Netlify is using yarn instead of npm correctly, as the repo does contain a yarn.lock file

Sorry to be slow to get back to you. hmm, interesting - is this problem still present? I am wondering if this might be a bug, but i’d need to get that confirmed.

This is still an issue yes.

Extract from logs of a build I just ran:

7:03:23 AM: Installing NPM modules using Yarn version 1.22.4
7:03:24 AM: yarn install v1.22.4

No flags being passed to yarn install

Thanks for confirming.

This error from your earlier-quoted seems pretty straightforward:

It means that your yarn registry is disallowing us access. What access methods are possible and what authentication have you configured to allow our build hosts access to your registry?

Right, the lack of access is something I’ve tried to fix by passing a --registry flag among other things.

I started this post because the YARN_FLAGS environment variable seems to be ignored, which should be apparent from the logs.
I’m not looking for support to fix the 403 error at the moment, I’m trying to understand why YARN_FLAGS is not working.

Hi, @Robin-Hoodie. There is a known bug where if there is more than one value in YARN_FLAGS (meaning, if there is a space in the value) then the environment variable isn’t parsed at all.

For example, this won’t work:

YARN_FLAGS = '--production=false --verbose'

However, either of these will:

YARN_FLAGS = '--production=false'
# or
YARN_FLAGS = '--verbose'

You might see if just the --registry option works (without --ignore-optional). However, it might be necessary to add an = so there is no space like so:

[build.environment]
    YARN_FLAGS = '--registry=https://npm.greensock.com/'

This might be enough to get the yarn install working.

About the bug, we will post an update here if the issue if known to be resolved.

Do we know if the YARN_FLAGS bug has been fixed yet?
I’m finding myself needing to use more than one Yarn flag again

Bonus question:

Is there any way to view the actual yarn install command including its flags in the Deployment logs?
If you can view the actual command being run in the logs, it’s much easier to debug

Hi, I just checked and it appears that the bug is yet to be fixed. Sadly, I don’t have an ETA either.

You could add an environment variable with the name NETLIFY_VERBOSE and value as TRUE. Note that, it would make the log too verbose and might make it difficult to read.

Right, thanks for the quick reply.

I don’t mind helping to implement a fix, any chance you could point me in the right direction?

Hi @Robin-Hoodie,

Thank you for the interest. But unfortunately, the code for this is private and thus, it won’t be possible for non-employees to fix this.

I’ll re-ping the developers to see if something can be changed for an immediate workaround or not.

Hi @Robin-Hoodie,

The developers have got this on their roadmap, but they just confirmed that you could write a PR for this if you wish. Here’s an inspiration: https://github.com/netlify/build-image/issues/496

Thanks, I opened a PR for the relevant issue: https://github.com/netlify/build-image/pull/620

Hi @Robin-Hoodie,

Thank you very much for the PR. The devs have already made a note of it, but I’ll still ping them once again to see if it can be reviewed/shipped sooner. Thank you for your help and patience.

Hey folks :wave:

For everyone following this thread, thanks to the awesome contribution by @Robin-Hoodie this has now been fixed in both xenial and focal build images. Example logs for both:

Let us know if you’re still experiencing issues and thank you all for your help and patience :pray:

You’re very welcome! Thanks for adding tests and releasing this in a timely manner :slight_smile:

1 Like

Hi, can you confirm it does work for “–no-ignore-optional”? I specifically need to install “typedoc” as an optional dependency, but then it’s not found, so I think it’s not installed in the first place despite YARN_FLAGS being correctly reckognized.

My config:

[build]
  publish = "generated/docs"
  command = "yarn typedoc"
  environment = { YARN_FLAGS = "--no-ignore-optional"}

It’s an open source repo using Lerna: GitHub - VulcanJS/vulcan-npm: A Lerna repo for Vulcan core packages - NPM version

May I ask why you’re planning to keep it as an optional dependency and not add it to dependencies, so you can simply avoid the flag?

You’re right, I could palliate this issue temporarily, since it’s a top dependency I can move it to dev deps. But in other scenario I might not be able to do so. I try to introduce a cleaner pattern regarding to deps in my apps:

  • deps for runtime deps
  • devDeps for build-time deps
  • optional for dev tools such as Storybook, Jest, Cypress.

I use this pattern because I think historically NPM package were not designed to have a build-step, since they ran directly on Node.js, so the dependency division has to be questioned in modern apps with a build-step. Putting everything in dev deps is not an optimal practice these days, optional are underused imo.

So publishing a built Storybook nested within a Next.js app requires optional deps for instance.

Fair enough. So I’m trying to look for documentation regarding that flag, but I’m not seeing one. I found this:

but that’s the opposite of what you’re trying to use.

Could you point me to the correct docs?

That’s a flag specicic to Netlify indeed, I don’t think it’s defined by Yarn, here is the doc :https://docs.netlify.com/configure-builds/manage-dependencies/