Skip to content

Cannot build SvelteKit app with @vitejs/plugin-legacy #3247

Description

@nicomouss

Describe 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-edge-caseSvelteKit cannot be used in an uncommon wayvite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions