Skip to content

NODE_ENV not inherited from .env file when running in a different mode #3983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RickMeijer opened this issue May 13, 2019 · 3 comments
Closed

Comments

@RickMeijer
Copy link

Version

3.7.0

Reproduction link

https://github.com/RickMeijer/bugreport-vuecli-environment

Environment info

  System:
    OS: macOS Mojave 10.14.4
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
  Binaries:
    Node: 10.13.0 - ~/.nvm/versions/node/v10.13.0/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v10.13.0/bin/npm
  Browsers:
    Chrome: 74.0.3729.131
    Firefox: 66.0.3
    Safari: 12.1
  npmGlobalPackages:
    @vue/cli: 3.7.0

Steps to reproduce

Either:

  • Clone project
  • npm run build
  • npm run build -- --mode=foo

Or:

  • Create new project
  • Create .env
  • In the .env file, set NODE_ENV to production
  • Create empty .env.foo
  • Run npm run build -- --mode=foo

What is expected?

NODE_ENV should be 'production'

According to the docs; all environments load the .env file. That should mean it also inherits the variables set therin.

What is actually happening?

NODE_ENV is 'development'

@RickMeijer
Copy link
Author

RickMeijer commented May 13, 2019

When setting NODE_ENV in the [mode] file, everything works as expected.
It becomes impossible to set a default though, contrary to every other environment variable.

@novbing
Copy link

novbing commented May 17, 2019

According to the official wiki, when you do npm run serve without --mode, it neans --mode=development. So process.env.NODE_ENV is 'development', even though you define it production in .env.

In this case, you can make a .env.development like below:

NODE_ENV=production
TITLE=inheritance works (from .env.development)

Then do npm run serve output console:
Current build environment is production
Fortunately, inheritance works (from .env.development)

wiki:
https://cli.vuejs.org/guide/cli-service.html#vue-cli-service-serve
https://cli.vuejs.org/guide/mode-and-env.html#modes

@makraz
Copy link

makraz commented Jan 18, 2020

Vue-cli Version: 3.7.0
Environment info
System:
OS: macOS Catalina 10.15.2
Binaries:
Node: v12.14.0
Yarn: 1.21.1
npm: 6.13.4
Browsers:
Chrome: Version 78.0.3904.108 (Official Build) (64-bit)

I have the same issue NODE_ENV not inherited from .env file when running in a different mode
but when i restart system and again the command take the env config

Scenario

I run build with : npm run build -- --mode development
the build done successfully after that i run the build with npm run build (also i tried npm run build -- --mode production)
the build done successfully but all config is inherited from .env.development and not from .env. production
but if i restart the system again and run npm run build (or npm run build -- --mode production) the build done successfully and it's work fine

so what i think is that the config is loaded on the RAM and when the mode is change vue-cli done update config in RAM

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

No branches or pull requests

3 participants