From 47184d4194f015442270a280b33ee850ba9b0f83 Mon Sep 17 00:00:00 2001 From: "T. R. Bernstein" <137705289+trbernstein@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:59:05 +0100 Subject: [PATCH] Use optional chaining to catch null error codes in error.js (#1054) * Use optional chaining to catch null error codes in error.js Starting a new vite project and selecting svelte-ts template results in an error, because `code` var in error.js is null. Optional chaining resolves this issue. * chore: add changeset --------- Co-authored-by: dominikg --- .changeset/giant-plants-learn.md | 5 +++++ packages/vite-plugin-svelte/src/utils/error.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/giant-plants-learn.md diff --git a/.changeset/giant-plants-learn.md b/.changeset/giant-plants-learn.md new file mode 100644 index 000000000..5142ca7c4 --- /dev/null +++ b/.changeset/giant-plants-learn.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/vite-plugin-svelte': patch +--- + +fix errorhandling to work with errors that don't have a code property diff --git a/packages/vite-plugin-svelte/src/utils/error.js b/packages/vite-plugin-svelte/src/utils/error.js index cbc375b2d..31e3c5af3 100644 --- a/packages/vite-plugin-svelte/src/utils/error.js +++ b/packages/vite-plugin-svelte/src/utils/error.js @@ -108,7 +108,7 @@ function formatFrameForVite(frame) { * @returns {boolean} */ function couldBeFixedByCssPreprocessor(code) { - return code === 'expected_token' || code === 'unexpected_eof' || code.startsWith('css_'); + return code === 'expected_token' || code === 'unexpected_eof' || code?.startsWith('css_'); } /**