Skip to content

Destructured env vars not replaced in --modern builds #4658

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
runarberg opened this issue Oct 7, 2019 · 1 comment · Fixed by #4673
Closed

Destructured env vars not replaced in --modern builds #4658

runarberg opened this issue Oct 7, 2019 · 1 comment · Fixed by #4673

Comments

@runarberg
Copy link

Version

4.0.0-rc.7

Reproduction link

https://github.com/runarberg/vue-cli-modern-process-env-fail

Environment info

$ npx @vue/cli@next info

Environment Info:

  System:
    OS: Linux 5.0 Ubuntu 19.04 (Disco Dingo)
    CPU: (4) x64 Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz
  Binaries:
    Node: 12.11.1 - ~/.nvm/versions/node/v12.11.1/bin/node
    Yarn: Not Found
    npm: 6.11.3 - ~/.nvm/versions/node/v12.11.1/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: 69.0
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0 
    @vue/babel-plugin-transform-vue-jsx:  1.0.0 
    @vue/babel-preset-app:  4.0.0-rc.7 
    @vue/babel-preset-jsx:  1.1.0 
    @vue/babel-sugar-functional-vue:  1.0.0 
    @vue/babel-sugar-inject-h:  1.0.0 
    @vue/babel-sugar-v-model:  1.0.0 
    @vue/babel-sugar-v-on:  1.1.0 
    @vue/cli-overlay:  4.0.0-rc.7 
    @vue/cli-plugin-babel: ^4.0.0-rc.7 => 4.0.0-rc.7 
    @vue/cli-plugin-eslint: ^4.0.0-rc.7 => 4.0.0-rc.7 
    @vue/cli-service: ^4.0.0-rc.7 => 4.0.0-rc.7 
    @vue/cli-shared-utils:  4.0.0-rc.7 
    @vue/component-compiler-utils:  3.0.0 
    @vue/preload-webpack-plugin:  1.1.1 
    @vue/web-component-wrapper:  1.2.0 
    eslint-plugin-vue: ^5.0.0 => 5.2.3 
    vue: ^2.6.10 => 2.6.10 
    vue-eslint-parser:  5.0.0 
    vue-hot-reload-api:  2.3.4 
    vue-loader:  15.7.1 
    vue-style-loader:  4.1.2 
    vue-template-compiler: ^2.6.10 => 2.6.10 
    vue-template-es2015-compiler:  1.9.1 
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

Destructure process.env somewhere in your code:

<template>
  <HelloWorld :msg="msg" />
</template>

<script>
const { VUE_APP_MSG: msg } = process.env;

export default {
  data() {
    return {
      msg,
    };
  },
};
</script>

Add the env var to your .env:

 VUE_APP_MSG="Hello, Bug!"

Then build with the --modern flag:

npm run build -- --modern

What is expected?

The build output should have the destructured env vars replaced. That is msg should be set to "Hello, Bug!".

What is actually happening?

This only happens in the legacy build. In the modern build the variable is undefined.


I think this is a regression. I think this worked as expected in vue-cli 3.

@haoqunjiang
Copy link
Member

haoqunjiang commented Oct 9, 2019

Caused by #3782. See the reasoning at #3579
I'm wondering if we can revert it though. I need to test it out locally.

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

Successfully merging a pull request may close this issue.

2 participants