From 159bdb9e90de4d045192848bb3f7affbbf40da9e Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Sun, 31 Aug 2025 14:06:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(#219):=20=E4=BF=AE=E6=94=B9dev=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E4=BB=A5=E6=94=AF=E6=8C=81Windows=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=99=A8=20ESM=E6=A8=A1=E5=9D=97=E5=9C=A8Win?= =?UTF-8?q?dows=E7=B3=BB=E7=BB=9F=E4=B8=8B=E7=9A=84=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- scripts/window-path-loader.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 scripts/window-path-loader.js diff --git a/package.json b/package.json index 79d09ca..91a6da3 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "dev:app-android": "uni -p app-android", "dev:app-ios": "uni -p app-ios", "dev:custom": "uni -p", - "dev": "uni", + "dev": "node --experimental-loader ./scripts/window-path-loader.js node_modules/@dcloudio/vite-plugin-uni/bin/uni.js", "dev:test": "uni --mode test", "dev:prod": "uni --mode production", "dev:h5": "uni", diff --git a/scripts/window-path-loader.js b/scripts/window-path-loader.js new file mode 100644 index 0000000..21f41b8 --- /dev/null +++ b/scripts/window-path-loader.js @@ -0,0 +1,29 @@ +// fix: https://github.com/unibest-tech/unibest/issues/219 + +// Windows path loader for Node.js ESM +// This loader converts Windows absolute paths to file:// URLs + +import { pathToFileURL } from 'node:url' + +/** + * Resolve hook for ESM loader + * Converts Windows absolute paths to file:// URLs + */ +export function resolve(specifier, context, defaultResolve) { + // Check if this is a Windows absolute path (starts with drive letter like C:) + if (specifier.match(/^[a-z]:\\/i) || specifier.match(/^[a-z]:\//i)) { + // Convert Windows path to file:// URL + const fileUrl = pathToFileURL(specifier).href + return defaultResolve(fileUrl, context, defaultResolve) + } + + // For all other specifiers, use the default resolve + return defaultResolve(specifier, context, defaultResolve) +} + +/** + * Load hook for ESM loader + */ +export function load(url, context, defaultLoad) { + return defaultLoad(url, context, defaultLoad) +}