3

Inside svelte.config.js I was using this

const dev = process.env.NODE_ENV === 'development';

to conditionally set a base path which was working fine in projects with @sveltejs/[email protected] and *.357

After installing now the most recent SvelteKit version @sveltejs/[email protected] it only results to undefined

Differences I notice is that the new project lists "vite": "^3.0.0" as devDependency and the script changed from "dev": "svelte-kit dev", to "dev": "vite dev"

Update: It's also the case for a project with @sveltejs/[email protected], [email protected], "dev": "vite dev" - so the switch was before vite 3.0

Going through the vite docs I find import.meta.env, but that's also undefined inside svelte.config.js

Switching from Node v16 to 17 didn't make a difference as well

What changed and how can I now distinguish between dev and build mode?

1
  • Hint: backticks do not work in question string. Commented Jul 21, 2022 at 17:27

2 Answers 2

5

The behavior you describe was introduced in 100-next384

[breaking] remove mode, prod and server from $app/env (#5602)

and here is the relevant discussion

respect --mode, and remove server, prod and mode from $app/env

I think you should use Vite capabilities to configure dev VS production/build modes.

Update

Considering better your case, a way to solve the issue is to set a value for the NODE_DEV environment variable, like (Linux/Mac):

export NODE_ENV=development && npm run dev

There are other ways to do this but at least for development it should do the trick.

Sign up to request clarification or add additional context in comments.

5 Comments

I'm not sure - is this really related to $app/env? I'm not in a src/ project file but in the svelte.config.js. I first thought it was only with the current version and somehow related to vite 3, but it's the same in a project with next.366 and [email protected]. The vite docs page you linked is where I got import.meta.env from which as stated unforunately doesn't work in the config file.
I see what you say. Then, shouldn't be enough to export NODE_ENV environment variable?
export how/where?
it depends on your environment/os. for linux development I run export NODE_ENV='dev' npm run dev. ymmv
I'm on Mac and export NODE_ENV=development && ... seems to be doing the trick, great! Thanks!!
0

This might help someone in the future. I encountered this error when I created an express server in a react application. I created the server directory in the root folder of the react application and I was running both react app and express server at the same time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.