Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(examples): resolve dev locale imports to file URLs on Windows (#7751)
INTER TERMUXdaee9a641a15
diff --git a/examples/scripts/export-locale.mts b/examples/scripts/export-locale.mtsindex ec415ea7ec..592a40e11f 100644--- a/examples/scripts/export-locale.mts+++ b/examples/scripts/export-locale.mts@@ -1,5 +1,7 @@import process from 'node:process';+import { resolveLocaleModuleUrl } from './locale-module-url.mts';+interface ILocaleModule {default?: unknown;}@@ -90,7 +92,12 @@ if (!isLocaleProduct(product) || !locale || !LOCALE_TAGS.has(locale)) {const source = LOCALE_SOURCES[product];const packs = await Promise.all(source.packages.map(async (packageName) => {- const module = await import(`${packageName}/${source.directory}/${locale}`) as ILocaleModule;+ // Import the resolved file:// URL instead of the bare specifier: on+ // Windows a bare dynamic import can degrade to a raw absolute path+ // (`C:\...`), which Node's ESM loader rejects with+ // ERR_UNSUPPORTED_ESM_URL_SCHEME.+ const moduleUrl = resolveLocaleModuleUrl(`${packageName}/${source.directory}/${locale}`);+ const module = await import(moduleUrl) as ILocaleModule;return unwrapDefault(module);}));diff --git a/examples/scripts/locale-module-url.mts b/examples/scripts/locale-module-url.mtsnew file mode 100644index 0000000000..dc3727ca23--- /dev/null+++ b/examples/scripts/locale-module-url.mts@@ -0,0 +1,13 @@+/**+ * Resolve a locale module specifier to a `file://` URL for dynamic import.+ *+ * The dev locale exporter used to pass the bare specifier straight to+ * `import()`. Under tsx on Windows that resolves to a raw absolute path like+ * `C:\...`, which Node's ESM loader rejects with+ * `ERR_UNSUPPORTED_ESM_URL_SCHEME` ("Received protocol 'c:'"). The failure+ * surfaces in the workbench as "Could not load <product> locale <tag>" on+ * every tab. Importing the resolved `file://` URL works on all platforms.+ */+export function resolveLocaleModuleUrl(specifier: string): string {+ return import.meta.resolve(specifier);+}