From cd6778576acb8fd7cf8b3fd1926ef3a4f6713511 Mon Sep 17 00:00:00 2001 From: Ryan Turnquist Date: Fri, 13 Dec 2024 16:25:52 -0800 Subject: [PATCH] fix: load translator with require when checking tags API --- .changeset/five-schools-complain.md | 5 +++++ src/index.ts | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/five-schools-complain.md diff --git a/.changeset/five-schools-complain.md b/.changeset/five-schools-complain.md new file mode 100644 index 0000000..0593d71 --- /dev/null +++ b/.changeset/five-schools-complain.md @@ -0,0 +1,5 @@ +--- +"@marko/vite": patch +--- + +Fix loading of translator when checking if tags API is being used" diff --git a/src/index.ts b/src/index.ts index 67f01bd..05b7600 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import anyMatch from "anymatch"; import crypto from "crypto"; import glob from "fast-glob"; import fs from "fs"; +import { createRequire } from "module"; import path from "path"; import { pathToFileURL } from "url"; import type * as vite from "vite"; @@ -661,8 +662,8 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] { tagsAPI = false; } else { try { - tagsAPI = - (await import(translatorPackage)).preferAPI !== "class"; + const require = createRequire(import.meta.url); + tagsAPI = require(translatorPackage).preferAPI !== "class"; } catch { tagsAPI = true; }