diff --git a/packages/tailwindcss-language-server/src/projects.ts b/packages/tailwindcss-language-server/src/projects.ts index 5d9e511a..b55ee078 100644 --- a/packages/tailwindcss-language-server/src/projects.ts +++ b/packages/tailwindcss-language-server/src/projects.ts @@ -19,7 +19,7 @@ import type { import { FileChangeType } from 'vscode-languageserver/node' import type { TextDocument } from 'vscode-languageserver-textdocument' import { URI } from 'vscode-uri' -import { showError, SilentError } from './util/error' +import { showError, showWarning, SilentError } from './util/error' import * as path from 'node:path' import * as fs from 'node:fs' import findUp from 'find-up' @@ -838,6 +838,15 @@ export async function createProjectService( originalConfig = await loadConfig.module(state.configPath) originalConfig = originalConfig.default ?? originalConfig state.jit = true + } catch (err) { + // The user's config failed to load in v3 so we need to fallback + originalConfig = await resolveConfig.module({}) + state.jit = true + + // And warn the user + console.error(`Unable to load config file at: ${state.configPath}`) + console.error(err) + showWarning(connection, 'Tailwind CSS is unable to load your config file', err) } finally { hook.unhook() } diff --git a/packages/tailwindcss-language-server/src/util/error.ts b/packages/tailwindcss-language-server/src/util/error.ts index 53222fcf..26698b74 100644 --- a/packages/tailwindcss-language-server/src/util/error.ts +++ b/packages/tailwindcss-language-server/src/util/error.ts @@ -32,6 +32,16 @@ export function showError( // } } +export function showWarning( + connection: Connection, + message: string = 'Tailwind CSS', + err: any, +): void { + connection.sendNotification('@/tailwindCSS/warn', { + message: formatError(message, err, false), + }) +} + export function SilentError(message: string) { this.name = 'SilentError' this.message = message diff --git a/packages/vscode-tailwindcss/CHANGELOG.md b/packages/vscode-tailwindcss/CHANGELOG.md index aee45d1d..23c8a373 100644 --- a/packages/vscode-tailwindcss/CHANGELOG.md +++ b/packages/vscode-tailwindcss/CHANGELOG.md @@ -10,6 +10,7 @@ - Make sure custom regexes apply in Vue `