Skip to content

Conversation

@hoah2333
Copy link

When using jsdom in a Svelte 5 environment, the build fails due to a syntax error in cssstyle.

I added jsdom to a Svelte 5 project and only used the following minimal code:

import { JSDOM } from "jsdom";

const dom = new JSDOM();

console.log(dom);

However, running vite build results in the following error:

✗ Build failed in 10.75s
error during build:
[vite-plugin-sveltekit-compile] [commonjs] node_modules/.pnpm/cssstyle@5.3.5/node_modules/cssstyle/lib/generated/properties.js (4759:0): Unexpected token `.`. Expected ... , *,  (, [, :, , ?, = or an identifier
file: D:/Svelte/cssstyle-test/node_modules/.pnpm/cssstyle@5.3.5/node_modules/cssstyle/lib/generated/properties.js:4759:0 (D:/Svelte/cssstyle-test/node_modules/.pnpm/jsdom@27.3.0/node_modules/jsdom/lib/jsdom/living/nodes/SVGDefsElement-impl.js)

4757:       definition: lineHeight_export_definition
4758:     }.parse(lineB, {
4759:       global
      ^
4760:     });
4761:     if (typeof lineHeightB !== "string") {

    at getRollupError (file:///D:/Svelte/cssstyle-test/node_modules/.pnpm/rollup@4.54.0/node_modules/rollup/dist/es/shared/parseAst.js:401:41)
    at ParseError.initialise (file:///D:/Svelte/cssstyle-test/node_modules/.pnpm/rollup@4.54.0/node_modules/rollup/dist/es/shared/node-entry.js:14534:28)       
    at convertNode (file:///D:/Svelte/cssstyle-test/node_modules/.pnpm/rollup@4.54.0/node_modules/rollup/dist/es/shared/node-entry.js:16418:10)
    at convertProgram (file:///D:/Svelte/cssstyle-test/node_modules/.pnpm/rollup@4.54.0/node_modules/rollup/dist/es/shared/node-entry.js:15658:12)
    at Module.setSource (file:///D:/Svelte/cssstyle-test/node_modules/.pnpm/rollup@4.54.0/node_modules/rollup/dist/es/shared/node-entry.js:17418:24)
    at async ModuleLoader.addModuleSource (file:///D:/Svelte/cssstyle-test/node_modules/.pnpm/rollup@4.54.0/node_modules/rollup/dist/es/shared/node-entry.js:21448:13)

This error originates from the following object literal in font.js

{
  global
}

The shorthand property syntax ({ global }) is not correctly handled by Rollup in this build setup, which causes the parser to throw a syntax error during bundling.

Replacing the shorthand property with an explicit key-value pair resolves the issue:

{
  global: global
}

After applying this change, vite build completes successfully in the Svelte 5 environment.

Disable `object-shorthand` eslint rule to ensure compatibility with
bundlers that fail to parse shorthand properties in this file.
@domenic
Copy link
Member

domenic commented Dec 24, 2025

This is a bug in Rollup, which you should report there.

@domenic domenic closed this Dec 24, 2025
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

Successfully merging this pull request may close these issues.

2 participants