-
-
Notifications
You must be signed in to change notification settings - Fork 968
Description
Clear and concise description of the problem
When using @unocss/svelte-scoped (both Vite plugin and preprocessor), users can specify a custom path to the UnoCSS config file using the configFile option. However, if the specified file doesn't exist, the plugin silently falls back to the default configuration without any warning or error.
This silent fallback can lead to confusing situations where users expect their custom configuration to be applied but instead get default behavior, making debugging unnecessarily difficult.
Current Behavior
// vite.config.ts
import UnoCSS from "@unocss/svelte-scoped/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
UnoCSS({
configFile: "./uno.config.custom.ts", // File doesn't exist
// Other options...
}),
sveltekit(),
],
});Result: Plugin continues to work with default configuration, no error is thrown.
Expected Behavior
When a custom configFile path is explicitly provided but the file doesn't exist, the plugin should throw a clear error message, such as:
Error: UnoCSS config file not found: ./uno.config.custom.ts
Please check the path or remove the configFile option to use the default config location.
Why This Matters
-
Explicit configuration should be validated - When users explicitly specify a config file path, they have a clear intent. Silent fallback contradicts this intent.
-
Faster debugging - Clear error messages save developers time by immediately identifying the problem rather than leaving them wondering why their configuration isn't being applied.
-
Consistent with common tooling patterns - Most build tools (Vite, Webpack, Rollup, etc.) throw errors when explicitly specified config files are not found.
-
Prevents silent failures in CI/CD - In automated environments, missing config files should fail loudly rather than deploying with unexpected default configuration.
Suggested solution
Add file existence validation when configFile option is provided:
- If
configFileis specified and the file doesn't exist → throw an error - If
configFileis not specified → continue with current default config resolution behavior
This validation should apply to both:
@unocss/svelte-scoped/vite(Vite plugin)@unocss/svelte-scoped/preprocess(Svelte preprocessor)
Comparison with Other UnoCSS Integrations
For consistency, it's worth noting that the main unocss/vite plugin follows the standard pattern of config file resolution but doesn't have this specific issue because it uses UnoCSS's core config loading mechanism differently. However, the principle of failing fast when explicitly provided configs are missing is widely adopted across the ecosystem.
Alternative
No response
Additional context
This issue is specifically about explicit user configuration. The default config file resolution (when configFile is not specified) should continue to work as it does currently - looking for uno.config.{ts,js,mjs} in standard locations and gracefully using defaults if none are found.
Edge Cases to Consider
- Typos in path - Most common cause of missing files
- Relative vs absolute paths - Error message should show the resolved absolute path
- Build vs dev mode - Validation should work consistently in both modes
Minimal Reproduction
# Create a SvelteKit project
npm create svelte@latest my-app
cd my-app
# Install dependencies
npm install @unocss/svelte-scoped
# Configure with non-existent file
# vite.config.ts - specify configFile: './non-existent.ts'
# Run dev server
npm run dev
# Expected: Clear error about missing config file
# Actual: Works with default config, no indication of problemEnvironment:
- Package:
@unocss/svelte-scoped - Versions: All current versions (tested with latest)
- Applies to: Both Vite plugin and preprocessor modes
- Frameworks: SvelteKit, Svelte with Vite, Svelte with svelte-package
Validations
- Read the Contributing Guidelines.
- Read the
README.mdof using the package. - Already used the Interactive Docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.