Cannot build SvelteKit app with `@vitejs/plugin-legacy`
See original GitHub issueDescribe the bug
In case some Vite plugins are set in the config, command npm run build
fails using latest SvelteKit version, whereas it was not failing using older versions.
Reproduction
npx degit https://github.com/nicomouss/sveltekit-build-fail.git sveltekit-build-fail
cd sveltekit-build-fail
npm install
npm run build
This successfully builds a basic SvelteKit skeleton app (with a Vite plugin added to its build config) based on a previous version of SvelteKit. You can check the libraries in use by running npm list --depth=0
, this should displays the following (= the setup you would have gotten by creating a SvelteKit app a couple weeks ago, like I did back then):
├── @sveltejs/adapter-static@1.0.0-next.22
├── @sveltejs/kit@1.0.0-next.201
├── @vitejs/plugin-legacy@1.6.4
├── svelte@3.44.2
Now let’s upgrade our app to the latest version of SvelteKit (= the setup you would get by creating a SvelteKit app as for now):
npm i -D @sveltejs/kit@1.0.0-next.218
npm i -D svelte@3.45.0
npm i -D @sveltejs/adapter-static@1.0.0-next.24
Then run npm run build
.
The build now fails with the following exception:
> Cannot read property 'filter' of undefined
Thus upgrading to latest SvelteKit version can break the build of an app.
In this case, there seems to be a side effect regarding Vite plugins. Because if you open svelte.config.js
and change it from this:
vite: {
plugins: [
legacy({
targets: ['defaults', 'not IE 11']
})
]
}
to this:
vite: {
plugins: []
}
Then the build works successfully again. Only you loose the plugin you have been successfully using till now…
Logs
No response
System Info
Latest published SvelteKit librairies
Severity
annoyance
Additional Information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (6 by maintainers)
Same problem here. As @benmccann pointed out, the issue is
await vite.build(config)
returns an array, not a single object. SvelteKit is trying to destructure {output} from[ { output: [Array] }, { output: [Array] } ] }
.My goal is to support legacy Safari on iPhone 4s.
As I said when this was closed, we already have an issue to track this. Please follow https://github.com/sveltejs/kit/issues/12