Describe the bug
Defined a constant in Vite config and used it in hooks.client.js, it result in ReferenceError: __SOME_THING__ is not defined.
This only affect dev server, and it only happens when used in top-level execution.
Reproduction
- Define a constant in vite.config.js
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
export default defineConfig({
define: {
__SOME_THING__: { key: 'value' }
},
plugins: [sveltekit()]
});
- Reference in hooks.client.js
console.log(__SOME_THING__);
- Start the dev server
Logs
hooks.client.js:1 Uncaught (in promise) ReferenceError: __SOME_THING__ is not defined
at hooks.client.js:1:13
(anonymous) @ hooks.client.js:1
System Info
System:
OS: macOS 15.2
CPU: (8) arm64 Apple M1
Memory: 77.94 MB / 16.00 GB
Shell: 3.7.1 - /opt/homebrew/bin/fish
Binaries:
Node: 22.12.0 - ~/.local/share/nvm/v22.12.0/bin/node
Yarn: 1.22.22 - /opt/homebrew/bin/yarn
npm: 10.9.0 - ~/.local/share/nvm/v22.12.0/bin/npm
pnpm: 9.15.1 - /opt/homebrew/bin/pnpm
Browsers:
Chrome: 131.0.6778.205
Safari: 18.2
npmPackages:
@sveltejs/adapter-auto: ^3.0.0 => 3.3.1
@sveltejs/kit: ^2.0.0 => 2.15.1
@sveltejs/vite-plugin-svelte: ^4.0.0 => 4.0.4
svelte: ^5.0.0 => 5.16.0
vite: ^5.4.11 => 5.4.11
Severity
annoyance
Describe the bug
Defined a constant in Vite config and used it in hooks.client.js, it result in
ReferenceError: __SOME_THING__ is not defined.This only affect dev server, and it only happens when used in top-level execution.
Reproduction
Logs
hooks.client.js:1 Uncaught (in promise) ReferenceError: __SOME_THING__ is not defined at hooks.client.js:1:13 (anonymous) @ hooks.client.js:1System Info
System: OS: macOS 15.2 CPU: (8) arm64 Apple M1 Memory: 77.94 MB / 16.00 GB Shell: 3.7.1 - /opt/homebrew/bin/fish Binaries: Node: 22.12.0 - ~/.local/share/nvm/v22.12.0/bin/node Yarn: 1.22.22 - /opt/homebrew/bin/yarn npm: 10.9.0 - ~/.local/share/nvm/v22.12.0/bin/npm pnpm: 9.15.1 - /opt/homebrew/bin/pnpm Browsers: Chrome: 131.0.6778.205 Safari: 18.2 npmPackages: @sveltejs/adapter-auto: ^3.0.0 => 3.3.1 @sveltejs/kit: ^2.0.0 => 2.15.1 @sveltejs/vite-plugin-svelte: ^4.0.0 => 4.0.4 svelte: ^5.0.0 => 5.16.0 vite: ^5.4.11 => 5.4.11Severity
annoyance