fix(examples): resolve dev locale imports to file URLs on Windows (#7751)

Co-authored-by: 白熱 <sonne@asaki.me>
This commit is contained in:
INTER TERMUX
2026-09-28 10:17:35 +08:00
committed by 白熱
co-authored by 白熱
parent e11a3897d9
commit daee9a641a
2 changed files with 21 additions and 1 deletions
+8 -1
View File
@@ -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);
}));
+13
View File
@@ -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);
}