From bb6e8800094dc59841eb3b345fcb8baca9e17ce9 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Tue, 1 Nov 2022 10:50:53 -0400 Subject: [PATCH] Prevent tailwind config errors from crashing dev server (#5270) * Prevent tailwind config errors from crashing dev server * Adding a changeset * Fix wrong type --- .changeset/long-turtles-run.md | 5 +++++ packages/integrations/tailwind/src/index.ts | 13 +++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 .changeset/long-turtles-run.md diff --git a/.changeset/long-turtles-run.md b/.changeset/long-turtles-run.md new file mode 100644 index 000000000..599c3c99a --- /dev/null +++ b/.changeset/long-turtles-run.md @@ -0,0 +1,5 @@ +--- +'@astrojs/tailwind': patch +--- + +Prevent errors during HMR from crashing dev server diff --git a/packages/integrations/tailwind/src/index.ts b/packages/integrations/tailwind/src/index.ts index bc4d820d5..fb75e34fe 100644 --- a/packages/integrations/tailwind/src/index.ts +++ b/packages/integrations/tailwind/src/index.ts @@ -40,13 +40,14 @@ async function getUserConfig(root: URL, configPath?: string, isRestart = false) const tempConfigPath = path.join(dir, `.temp.${Date.now()}.${base}`); await fs.copyFile(resolvedConfigPath, tempConfigPath); - const result = await load('tailwind', { - mustExist: false, - cwd: resolvedRoot, - filePath: tempConfigPath, - }); - + let result: load.Config> | undefined; try { + result = await load('tailwind', { + mustExist: false, + cwd: resolvedRoot, + filePath: tempConfigPath, + }); + await fs.unlink(tempConfigPath); } catch { /** file already removed */