question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

npm run build --mode [.env.mode] not working as expected

See original GitHub issue

Version

3.0.0-beta.16

Reproduction link

https://codesandbox.io/s/qlx254n09j

Steps to reproduce

  1. Create .env.staging file in the root
  2. Add key pairs NODE_ENV=production and VUE_APP_ENV=staging in the file
  3. Add script to package.json "staging":"vue-cli-service build --mode staging",
  4. Run npm run build --mode staging
  5. Run npm run staging

What is expected?

Case 1

npm run buid --mode staging

gives a production oriented build with staging variables

Case 2

npm run staging

gives a production oriented build with staging variables

What is actually happening?

Case 1

It gives a production oriented build with production variables

Case 2

It gives a development oriented build with staging variables


I need this to deploy this to Heroku. CD/CI. I’m using postinstall script to build production, dev or staging servers based on the APP_VUE_ENV variable. Please help me. I’m super excited with Vue so far!

Reference:

https://cli.vuejs.org/guide/mode-and-env.html#example-staging-mode https://github.com/vuejs/vue-cli/issues/948 https://forum.vuejs.org/t/how-to-build-production-app-with-varying-config/29708

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

68reactions
LinusBorgcommented, Jun 9, 2018

This is related to how npm passes arguments to scripts when using npm run

# passes the `mode` argument to npm
npm run build --mode staging

#passes the `mode` argument to vue-cli service`
npm run build -- --mode staging

In other words: all arguments before -- are interpreted as arguments for npm itself, not the script you are running.

1reaction
yyx990803commented, Jun 9, 2018

This seems to be a regression introduced in #1503

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm run build --mode [.env.mode] not working as expected
As expected, running the command npm run build --mode staging is to give a production build with variable as listed in the .env.staging...
Read more >
Vue.js – npm run build –mode [.env.mode] not working as expected ...
What I've done so far: I've been trying to setup multiple build modes like staging , testing , production and development based on...
Read more >
npm run build --mode [.env.mode] not working as expected ...
I was having the same problem, I figured out my problem was from using a beta version ( 3.0.0-beta.9 ) of @vue/cli-service so...
Read more >
Create-react-app environments - Medium
env file. The value of NODE_ENV is set automatically to development (when using npm start ), test (when using npm test ) ...
Read more >
cross-env - npm
Run scripts that set and use environment variables across platforms. NOTICE: cross-env still works well, but is in maintenance mode.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found