storyblok / gatsby-storyblok-boilerplate

Gatsby starter template with Storyblok's headless cms and true preview
https://www.storyblok.com/tp/add-a-headless-cms-to-gatsby-5-minutes
BSD Zero Clause License
37 stars 28 forks source link

Error when using environment variable for token definition #6

Closed ajmueller closed 4 years ago

ajmueller commented 5 years ago

I was following your tutorial, but made a modification to gatsby-config.js: I used an environment variable to define my Storyblok token. When running the develop command, I get the following error:

This dependency was not found:
⠀
* fs in ./node_modules/dotenv/lib/main.js

This is due to line 4 in pages/editor.js that imports the gatsby-config.js file. It seems that the simplest solution may be to always use an environment variable for the token and ensure it's prefixed with GATSBY_ to make it available to the client side code. I'm happy to prepare a PR for this if that approach is okay with you.

emanuelgsouza commented 4 years ago

Hi, thanks for submitting your issue.

I believe that is solution of using GATSBY_ is the better, such as recommended by the official documentation.

About the problem relates to import the gatsby-config.js: according to the documentation, it's necessary to import dotenv package to use the environment variables, but, when we import the config file in editor.js (client side), we have an error, like you report.

So, you can use the environment variables from your shell or before to run the develop or build command, like this section describes.