Skip to content
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

NODE_ENV environment variable is undefined in svelte.config.js during during development (npm run dev) #5456

Closed
kelvindecosta opened this issue Jul 10, 2022 · 3 comments
Labels

Comments

@kelvindecosta
Copy link

Describe the bug

When used in svelte.config.js, process.env.NODE_ENV is undefined during development (npm run dev).
It is expected to be development.

This bug doesn't appear during production builds.
In other words, process.env.NODE_ENV is production, which is the expected value.

Reproduction

Reproduction on StackBlitz.

Please find the simple console statement that outputs the process.env.NODE_ENV value.

Logs

No response

System Info

System:
    OS: Linux 5.10 Manjaro Linux
    CPU: (8) x64 Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz
    Memory: 9.81 GB / 15.52 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v16.15.0/bin/yarn
    npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
  Browsers:
    Brave Browser: 101.1.38.111
    Firefox: 100.0
  npmPackages:
    @sveltejs/adapter-vercel: next => 1.0.0-next.60 
    @sveltejs/kit: next => 1.0.0-next.367 
    svelte: ^3.48.0 => 3.48.0 
    vite: ^2.9.13 => 2.9.13

Severity

annoyance

Additional Information

AFAIK, this bug appeared after the addition of the vite.config.js file.

@bluwy bluwy added the vite label Jul 11, 2022
@Conduitry
Copy link
Member

Per @bluwy, this looks like a bug in Vite. Checking for 'production' vs undefined instead of 'production' vs 'development' sounds like a reasonable workaround for the time being.

@kelvindecosta
Copy link
Author

@Conduitry, yes that makes perfect sense!

In that case do I close the issue?

@Rich-Harris
Copy link
Member

Yeah, this is outside SvelteKit's control. If you want a specific value you can either rely on Vite to set it, or do this:

NODE_ENV=development npm run dev

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

No branches or pull requests

4 participants