$NETLIFY_CACHE_DIR no longer defined?

Here is my build command for building my Elm site:

'export ELM_HOME="$NETLIFY_CACHE_DIR/elm" && echo "$ELM_HOME" && elm make ./src/Main.elm --output=static/assets/js/shallweplay.js'

This used to work as of May 17th, 2020. But now it fails:

5:55:45 PM: $ export ELM_HOME="$NETLIFY_CACHE_DIR/elm" && echo "$ELM_HOME" && elm make ./src/Main.elm --output=static/assets/js/shallweplay.js

5:55:45 PM: /elm

5:55:45 PM: elm:

5:55:45 PM: /elm: createDirectory: permission denied (Permission denied)  

I believe my build is failing because the cache directory path is wrong. It appears as though $NETLIFY_CACHE_DIR is no longer defined? I’m a Netlify noobie. I assumed this was set automatically by the Netlify build environment.

Thanks for the help.

As a side-note, I have fixed the issue by manually creating an environment variable called NETLIFY_CACHE_DIR and setting its value to /opt/buildhome/cache. But this is actually beside the point. I’d like to understand what changed to cause my site build to fail.

Hi, @dbj, it looks like that environment variable stopped working in the build system. I don’t see that environment variable documented as a useable environment variable during the build process anywhere.

We do mention check the value of that variable in the source code for the build-image here:

But that documentation doesn’t say to use the variable in the running build system, it says to check the value in the source code itself.

Even when I check the version of that file prior to May 20th, the variable is defined but not exported:

To summarize, this variable isn’t documented as an environment variable and I’m not ever seeing it as an exported environment variable where it is defined. Nothing changed as far as I can see relating to that variable so I suspect that the change in behavior is related to something else.

Thank you for your reply Luke. Very strange. I’ll consult others who I know were/are using it and see what they say.

:slight_smile:

Here is an article on the Elm forums showing it working recently:

We’ve been finding this to work now:

[build]
  publish = "./dist/"
-  command = "export ELM_HOME=\"$NETLIFY_CACHE_DIR/elm\" && npm run build"
+  command = "export ELM_HOME=\"$NETLIFY_BUILD_BASE/cache/elm\" && npm run build"

Does this match recommended practices?

Hey @dbj and @dillonkearns,
Our recommendation for custom cache handling is the cache utility of our build plugins (now out of beta and in GA :tada:):

Do you want to take a look at this plugin, which will likely be available in our UI shortly and is already available on npm, and see if it will work for the Elm cache?

1 Like

Yes. I was able to get this setup to work:

[build]
publish = "dist"
command = "export ELM_HOME=\"elm-stuff\" && npm run build"

[[plugins]]
package = "netlify-plugin-cache"
  [plugins.inputs]
  paths = ["elm-stuff"]

Thank you.

3 Likes