svelte: Newline in child element text causes parse error in Svelte 5.17.4
Describe the bug
Starting with Svelte 5.17.4, there is a parse error when the text passed as a child element contains a newline.
Occurring on Windows using VS Code in runes mode.
Reproduction
Attaching images and uploading with “txt” extension as uploading “svelte” files isn’t supported.
Logs
PS C:\cr-bitbucket\RMP Platform Scala\w2e-svelte\svelteui> npm run dev
> svelteui@0.0.1 dev
> vite dev
VITE v6.0.7 ready in 4361 ms
➜ press h + enter to show help
09:45:47 [vite] (client) Pre-transform error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
Plugin: vite:import-analysis
File: C:/cr-bitbucket/RMP Platform Scala/w2e-svelte/svelteui/src/lib/components/items/dialogs/CustomPanel.svelte:20:33
18 | $.next();
19 |
\nSecond line'); var text = $.text('First line
| ^
21 |
09:45:47 [vite] Internal server error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
Plugin: vite:import-analysis
File: C:/cr-bitbucket/RMP Platform Scala/w2e-svelte/svelteui/src/lib/components/items/dialogs/CustomPanel.svelte:20:33
18 | $.next();
19 |
\nSecond line'); var text = $.text('First line
| ^
21 |
22 | $.append($$anchor, text);
at TransformPluginContext._formatError (file:///C:/cr-bitbucket/RMP%20Platform%20Scala/w2e-svelte/svelteui/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:47397:41)
at TransformPluginContext.error (file:///C:/cr-bitbucket/RMP%20Platform%20Scala/w2e-svelte/svelteui/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:47392:16)
at TransformPluginContext.transform (file:///C:/cr-bitbucket/RMP%20Platform%20Scala/w2e-svelte/svelteui/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:45593:14)
at async EnvironmentPluginContainer.transform (file:///C:/cr-bitbucket/RMP%20Platform%20Scala/w2e-svelte/svelteui/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:47223:18)
at async loadAndTransform (file:///C:/cr-bitbucket/RMP%20Platform%20Scala/w2e-svelte/svelteui/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:41034:27)
at async viteTransformMiddleware (file:///C:/cr-bitbucket/RMP%20Platform%20Scala/w2e-svelte/svelteui/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:42478:24)
System Info
PS C:\cr-bitbucket\RMP Platform Scala\w2e-svelte\svelteui> npx envinfo --system --npmPackages svelte,rollup,webpack --binaries --browsers
System:
OS: Windows 11 10.0.22631
CPU: (12) x64 12th Gen Intel(R) Core(TM) i7-1265U
Memory: 16.55 GB / 31.69 GB
Binaries:
Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
npm: 10.9.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Chromium (130.0.2849.68)
Internet Explorer: 11.0.22621.3527
npmPackages:
svelte: ^5.17.4 => 5.17.4
Severity
blocking an upgrade
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (7 by maintainers)
I think, I’m hitting the same kind of error. Please see the CI logs. It only occurs on the Windows runner (Linux and Mac are fine).
Reverting
esrapfrom1.4.2to1.3.2fixes the issue. I’m using Svelte5.17.3, because5.17.4requiresesrap1.4.2, which also doesn’t build on Windows.Hopefully this provides some additional context.
I can confirm, the issue does seem to be due to the esrap version. With svelte 5.17.4 the issue disappears if I force the use of esrap 1.3.2 and comes back if I force the use of esrap 1.4.2 via the “overrides” in the package.json.