Support Forums

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:

    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:

    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.