Skip to content
This repository has been archived by the owner on Dec 24, 2021. It is now read-only.

Environment variables unavailable #157

Open
simondahla opened this issue Jan 23, 2019 · 6 comments
Open

Environment variables unavailable #157

simondahla opened this issue Jan 23, 2019 · 6 comments

Comments

@simondahla
Copy link

- Do you want to request a feature or report a bug?
Bug

- What is the current behavior?
None of the environment variables are picked up from the project .env file nither from the flags added to the build script in package.json

- If the current behavior is a bug, please provide the steps to reproduce.

When adding the following code to one of the templates

  {{ if eq (getenv "NODE_ENV") "development" }}
  console.log('You\'re in development!');
  {{ end }}
  
  {{ if eq (getenv "NODE_ENV") "production" }}
  console.log('You\'re in production!');
  {{ end }}

It returns nothing even tho the .env is set to development or when running npm build

- What is the expected behavior?

Be able to read environment variables within the templates

- Please mention your node.js, NPM, Hugo and operating system version.

Node: v10.13.0
NPM: v6.6.0

Hugo Static Site Generator v0.53/extended darwin/amd64 BuildDate: unknown
GOOS="darwin"
GOARCH="amd64"
GOVERSION="go1.11.4"

@simondahla
Copy link
Author

Also, in the previous version of victor-hugo (the last one using gulp) you were able to read all values from package.json e.g. version number

@ElanHasson
Copy link

I'm seeing this issue also. It constantly thinks I'm in production.

@brandlewco
Copy link

same issue here as well.

@erquhart
Copy link
Contributor

Based on the recent failed build for this repo, it seems we're not setting a mode for webpack: https://app.netlify.com/sites/victor-hugo/deploys/5bdb67f673f2cf1cc3280d06

@AudiLiew
Copy link

AudiLiew commented Sep 4, 2019

I tried setting the environment value again in the build:hugo script and it works.

"build:hugo": "cross-env NODE_ENV=production hugo -d ../dist -s site -v",

@timtorres
Copy link

timtorres commented Jul 12, 2021

I'm see this too and tried something similar to @AudiLiew, changed the following in order to get the snippet in the readme to work:
"start": "run-p start:**"
to
"start": "cross-env NODE_ENV=development run-p start:**"

I'm pretty new to this but it seems like an easy fix and I'm not sure why it hasn't been updated since 2019?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants