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

Unable to set Vite mode in development #5162

Closed
vdvman1 opened this issue Jun 5, 2022 · 5 comments
Closed

Unable to set Vite mode in development #5162

vdvman1 opened this issue Jun 5, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@vdvman1
Copy link

vdvman1 commented Jun 5, 2022

Describe the bug

It is supposed to be possible to set the Vite mode like this:

const config = {
	kit: {
		// Other options
		vite: {
			mode: "custom",
		},
	}
};

In production this works correctly, with .env.<mode> files being loaded and import.meta.env.MODE === "custom"

However in development the mode seems to always be set to "development". .env.development gets loaded, and import.meta.env.MODE === "development", despite the setting.

I do not know if this is a SvelteKit bug, a Vite bug, or that I am misunderstanding something about how Vite modes work. However I would expect this to always run with the Vite mode set to "custom"

Reproduction

Set kit -> vite -> mode in svelte.config.js to any string in the basic SvelteKit project created by the cli, and check the mode value using import.meta.env.MODE.
Build with npm run svelte-kit build and notice that the mode matches the string.
But run a dev server with npm run svelte-kit dev and notice that the mode is "development"

A repository with a reproduction can be found here
This repo always sets the vite mode to "custom", and displays the current vite mode in an h2 in index.svelte.
Using npm run build and previewing with npm run preview shows that the mode was correctly set to "custom".
However when using npm run dev to run a dev server the mode is displayed as "development"

Logs

No response

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (16) x64 AMD Ryzen 7 2700X Eight-Core Processor
    Memory: 22.04 GB / 31.92 GB
  Binaries:
    Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (101.0.1210.53)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @sveltejs/adapter-static: ^1.0.0-next.34 => 1.0.0-next.34
    @sveltejs/kit: next => 1.0.0-next.348
    svelte: ^3.44.0 => 3.48.0

Severity

serious, but I can work around it

Additional Information

I am trying to build my web app for both Github Pages and for Tauri, where the Tauri version can have more features. One way I am attempting to support this is using Vite modes to enable/disable/change features. Currently I am unable to test this in development, as the Vite mode is always giving "development".

In my actual repository I am setting an environment variable and changing the mode based on that env variable, as described in #1258 (via cross-env to work cross-platform)

@benmccann
Copy link
Member

We're actively working on this section of code right now and I wonder if we inadvertently broke something. Does this also happen with 1.0.0-next.345?

@vdvman1
Copy link
Author

vdvman1 commented Jun 7, 2022

This bug does not appear to occur in 1.0.0-next.345, I did npm install --save-dev @sveltejs/[email protected] in the repro project and removed the ^ that npm automatically inserted, and the Vite mode appears to be custom all both npm run build and in npm run dev

@benmccann
Copy link
Member

I believe this should be fixed in @sveltejs/[email protected]

@benmccann benmccann added the bug Something isn't working label Jun 7, 2022
@vdvman1
Copy link
Author

vdvman1 commented Jun 8, 2022

I have just tested it, and it does indeed appear to be fixed. Thanks!

@jsonkao
Copy link

jsonkao commented Feb 15, 2024

Btw, this should be configured in vite.config.js rather than svelte.config.js -> kit -> vite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants