Skip to content

CSS file present in src/routes/ breaks production build #3997

@yanneves

Description

@yanneves

Describe the bug

If a non-empty .css file is present in the src/routes/ directory with the same name as a .svelte file in the same directory, we receive an error in build.

Reproduction

To reproduce using the SvelteKit skeleton project:

  1. npm init svelte@next sveltekit-css-repro (select skeleton, no to all options)
  2. cd sveltekit-css-repro/
  3. npm install
  4. npm run build (succeeds)
  5. echo "h1 { font-size: 1.5em; }" > src/routes/index.css
  6. npm run build (fails, log below)
  7. mv src/routes/{index,index-styles}.css
  8. npm run build (succeeds)

Logs

$ npm run build

> [email protected] build
> svelte-kit build

vite v2.8.4 building for production...
✓ 13 modules transformed.
.svelte-kit/output/client/_app/manifest.json                    1.15 KiB
.svelte-kit/output/client/_app/layout.svelte-ddbe22e6.js        0.53 KiB / gzip: 0.35 KiB
.svelte-kit/output/client/_app/error.svelte-60b5f229.js         1.56 KiB / gzip: 0.75 KiB
.svelte-kit/output/client/_app/pages/index.svelte-4fdc3974.js   0.80 KiB / gzip: 0.47 KiB
.svelte-kit/output/client/_app/start-0e28adf2.js                23.61 KiB / gzip: 8.09 KiB
.svelte-kit/output/client/_app/chunks/vendor-f0095a1c.js        7.21 KiB / gzip: 2.96 KiB
vite v2.8.4 building SSR bundle for production...
✓ 12 modules transformed.
.svelte-kit/output/server/manifest.json                    0.87 KiB
.svelte-kit/output/server/app.js                           64.10 KiB
.svelte-kit/output/server/entries/pages/layout.svelte.js   0.24 KiB
.svelte-kit/output/server/entries/pages/error.svelte.js    0.72 KiB
.svelte-kit/output/server/entries/pages/index.svelte.js    0.32 KiB
.svelte-kit/output/server/chunks/index-2dc61825.js         2.29 KiB
> Cannot read properties of undefined (reading 'file')
    at file:///home/yann/git/sveltekit-css-repro/node_modules/@sveltejs/kit/dist/chunks/index4.js:78:108
    at Array.map (<anonymous>)
    at generate_manifest (file:///home/yann/git/sveltekit-css-repro/node_modules/@sveltejs/kit/dist/chunks/index4.js:71:14)
    at build (file:///home/yann/git/sveltekit-css-repro/node_modules/@sveltejs/kit/dist/chunks/index3.js:637:46)
    at async file:///home/yann/git/sveltekit-css-repro/node_modules/@sveltejs/kit/dist/cli.js:1054:23

System Info

System:
  OS: Linux 5.10 Debian GNU/Linux 10 (buster) 10 (buster)
  CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
  Memory: 8.23 GB / 15.60 GB
  Container: Yes
  Shell: 5.0.3 - /bin/bash
Binaries:
  Node: 17.5.0 - ~/.nvm/versions/node/v17.5.0/bin/node
  Yarn: 1.22.17 - ~/.nvm/versions/node/v17.5.0/bin/yarn
  npm: 8.5.1 - ~/.nvm/versions/node/v17.5.0/bin/npm
npmPackages:
  @sveltejs/adapter-auto: next => 1.0.0-next.17
  @sveltejs/kit: next => 1.0.0-next.278
  svelte: ^3.44.0 => 3.46.4

Severity

serious, but I can work around it

Additional Information

Further discussion in Svelte Discord thread https://discord.com/channels/457912077277855764/944288129114861588. Thanks to nudge#9063 for the help diagnosing!

A workaround is fairly trivial, ensure .css files inside src/routes/**/* do not match the filename of a .svelte file in the same directory.

The error is unclear, though. In a medium to large sized SvelteKit project, this could present a challenge upgrading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions