Skip to content

Svelte v5 with no emitCss specified throws error for missing .css file #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nolanlawson opened this issue Nov 11, 2023 · 1 comment
Closed

Comments

@nolanlawson
Copy link

If you don't define emitCss in the config passed to rollup-plugin-svelte, and you're using [email protected], and your component is missing a .css file, then an error is thrown:

[!] (plugin svelte) TypeError: Cannot read properties of null (reading 'code')
Hello.svelte
    at Object.transform (/workspace/rollup-demo/node_modules/rollup-plugin-svelte/index.js:154:32)
    at /workspace/rollup-demo/node_modules/rollup/dist/shared/rollup.js:1008:40

The error is thrown from this line:

if (emitCss && compiled.css.code) {

This same error does not occur with Svelte v4.

Here is a minimal repro.

You can repro by doing:

git clone https://gist.github.com/nolanlawson/91dac64f8f50aa9d61bb23e23d077ddf repro
cd repro
npm install --legacy-peer-deps
npx rollup -c

Node and npm versions:

$ node --version
v20.9.0
$ npm --version
9.9.1

As a workaround, you can set emitCss: false in the config.

@gka
Copy link

gka commented Feb 20, 2024

I noticed that when setting emitCss: false in the config, the styles won't get injected at all, so I don't think the workaround is really working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants