gridsome / gridsome/gridsome

Environment variables not working in main.js

Open
#819 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
8.5k
Forks
466
PR merge metrics
No merged PRs in 30d

Description

## Description

For some reason, I cannot interpolate env variables in code alike
```js
[...]
const accessToken = process.env.AUTH_TOKEN

export default function(Vue, { router, head, isClient }) {
Vue.use(PrismicVue, {
endpoint: process.env.PRISMIC_ENDPOINT,
linkResolver,
apiOptions: { accessToken },
})
}
```
the `AUTH_TOKEN` and `PRISMIC_ENDPOINT` variables are just not taken into account.
It does work everywhere else but not in this file.

### Steps to reproduce

I pretty much ran a stock gridsome project out of the box, trying to get `Prismic.io` to work. Nothing too fancy, I may add a demo if **really** needed.

### Expected result

As far as the [docs are saying](https://gridsome.org/docs/environment-variables/#usage-on-the-server), I could use `process.env.AUTH_TOKEN` to get an interpolated variable everywhere (`main.js` file included).

### Actual result

It returns `undefined`, even in some `${process.env.AUTH_TOKEN}` way. Oh and my key is totally working too. :+1:

Great news tho, I found that [solution](https://github.com/gridsome/gridsome/issues/88#issuecomment-451006295) to work actually ! I wished to know if it was an intended behavior (maybe add a line in the docs in that case) or if it is a bug.

Thanks ! :pray:

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the environment-variable usage in main.js and compare it with the server usage described in the linked documentation. Review the solution referenced from issue #88 to determine whether this is an intended limitation or a bug; done means the behavior is confirmed and either documented or corrected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.