Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Pass Env Vars to Sass Plugin in Gatsby?

How do I pass environment variables to the gatsby-sass-plugin? I'd like to be able to pass an environment variable into the loader that I can then use in my scss files. This is not well documented and I'm not sure how to do it.

Reference: https://www.gatsbyjs.com/plugins/gatsby-plugin-sass/

This does not work:

{
  resolve: "gatsby-plugin-sass",
  options: {
    additionalData: `$storeName: ${process.env.SHOPIFY_STORE_NAME};`
  }
},
like image 995
Jason Biondo Avatar asked Dec 05 '25 06:12

Jason Biondo


1 Answers

According to this recent GitHub thread, those options are not directly valid as it:

Invalid options object. Sass Loader has been initialized using an options object that does not match the API schema.

This is causing the options object to be undefined.

Try upgrading your gatsby-plugin-sass to:

[email protected]

Check your node-sass version too.

like image 169
Ferran Buireu Avatar answered Dec 07 '25 21:12

Ferran Buireu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!