Conditional configuration in vite.config.js breaks prod build
See original GitHub issueDescribe the bug
If your vite.config.js
uses conditional configuration, Svelte stops trying to compile components files to JS during SSR, and the resulting build fails because Rollup/Acorn is trying to parse Svelte files as JS.
Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-4wrfgp
Logs
❯ npm run build
$ vite build
vite v2.9.13 building for production...
✓ 34 modules transformed.
.svelte-kit/output/client/_app/immutable/assets/svelte-logo-87df40b8.svg 1.85 KiB
.svelte-kit/output/client/_app/immutable/assets/fira-mono-cyrillic-ext-400-normal-3df7909e.woff2 15.40 KiB
.svelte-kit/output/client/_app/immutable/assets/fira-mono-cyrillic-400-normal-c7d433fd.woff2 8.89 KiB
.svelte-kit/output/client/_app/immutable/assets/fira-mono-greek-ext-400-normal-9e2fe623.woff2 7.33 KiB
.svelte-kit/output/client/_app/immutable/assets/fira-mono-greek-400-normal-a8be01ce.woff2 10.27 KiB
.svelte-kit/output/client/_app/immutable/assets/fira-mono-latin-ext-400-normal-6bfabd30.woff2 11.10 KiB
.svelte-kit/output/client/_app/immutable/assets/fira-mono-latin-400-normal-e43b3538.woff2 15.90 KiB
.svelte-kit/output/client/_app/immutable/assets/fira-mono-all-400-normal-1e3b098c.woff 75.55 KiB
.svelte-kit/output/client/_app/immutable/manifest.json 2.67 KiB
.svelte-kit/output/client/_app/immutable/start-ab798b44.js 23.25 KiB / gzip: 8.72 KiB
.svelte-kit/output/client/_app/immutable/pages/__layout.svelte-f0707ee1.js 4.77 KiB / gzip: 1.86 KiB
.svelte-kit/output/client/_app/immutable/error.svelte-c8df2b3e.js 1.56 KiB / gzip: 0.75 KiB
.svelte-kit/output/client/_app/immutable/pages/about.svelte-692f0ea0.js 2.51 KiB / gzip: 1.15 KiB
.svelte-kit/output/client/_app/immutable/pages/index.svelte-471ba9cf.js 5.47 KiB / gzip: 2.42 KiB
.svelte-kit/output/client/_app/immutable/pages/todos/index.svelte-dda24c9b.js 6.86 KiB / gzip: 2.89 KiB
.svelte-kit/output/client/_app/immutable/chunks/index-9fe72fd8.js 11.81 KiB / gzip: 5.02 KiB
.svelte-kit/output/client/_app/immutable/chunks/index-92d65ea7.js 0.43 KiB / gzip: 0.30 KiB
.svelte-kit/output/client/_app/immutable/chunks/singletons-d1fb5791.js 0.05 KiB / gzip: 0.07 KiB
.svelte-kit/output/client/_app/immutable/assets/pages/__layout.svelte-da7c5ce3.css 5.08 KiB / gzip: 1.56 KiB
.svelte-kit/output/client/_app/immutable/assets/pages/about.svelte-bf4528fa.css 0.11 KiB / gzip: 0.10 KiB
.svelte-kit/output/client/_app/immutable/assets/pages/index.svelte-e12bfb09.css 1.45 KiB / gzip: 0.52 KiB
.svelte-kit/output/client/_app/immutable/assets/pages/todos/index.svelte-a910a02d.css 3.70 KiB / gzip: 1.03 KiB
vite v2.9.13 building SSR bundle for production...
✓ 0 modules transformed.
transforming (1) .svelte-kit/build/index.js[rollup-plugin-dynamic-import-variables] Unexpected token (1:0)
file: /home/projects/sveltejs-kit-template-default-4wrfgp/src/routes/__layout.svelte:1:0
[vite-plugin-svelte-kit] Unexpected token (1:0)
file: /home/projects/sveltejs-kit-template-default-4wrfgp/src/routes/__layout.svelte:1:0
System Info
System:
OS: Linux 5.0 undefined
CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.10 - /bin/yarn
npm: 7.17.0 - /bin/npm
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.53
@sveltejs/kit: next => 1.0.0-next.359
svelte: ^3.46.0 => 3.48.0
vite: ^2.9.13 => 2.9.13
Severity
blocking an upgrade
Additional Information
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Configuring Vite
vite.config.js export default { // config options } ... vite dev , and vite serve are aliases), and build when building for production...
Read more >Build Options - Vite
The deps paths are relative to the build.outDir . Returning a relative path to the hostId for hostType === 'js' is allowed, in...
Read more >Building for Production - Vite
You can configure how chunks are split using build.rollupOptions.output.manualChunks (see Rollup docs). Until Vite 2.8, the default chunking strategy ...
Read more >Configuring Vite
vite.config.js export default { // config options } ... If the config needs to conditional determine options based on the command ( dev...
Read more >Just-in-Time Mode - Tailwind CSS
Since development builds are as small as production builds, ... it's crucial that you configure the purge option in your tailwind.config.js file with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sadly not. An older version did that, which led to issues. See https://github.com/sveltejs/kit/issues/5308
Bummer. All right, I’ve opened a PR that keeps the
get_vite_config
function but now passes it avite_config_env
object.