Skip to content

Commit e190d8d

Browse files
authored
fix(dts): tsgo bin path should begin with file protocol in windows (#1211)
1 parent 7c2e87c commit e190d8d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/plugin-dts/src/tsgo.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
22
import fsP from 'node:fs/promises';
33
import { createRequire } from 'node:module';
44
import path from 'node:path';
5+
import { pathToFileURL } from 'node:url';
56
import { logger } from '@rsbuild/core';
67
import color from 'picocolors';
78
import type ts from 'typescript';
@@ -29,7 +30,16 @@ const getTsgoBinPath = async (): Promise<string> => {
2930
'./lib/getExePath.js',
3031
);
3132

32-
return import(libPath).then((mod) => {
33+
// handle Windows paths
34+
// On Windows, absolute paths must be valid file:// URLs
35+
let fileUrl: string;
36+
if (process.platform === 'win32') {
37+
fileUrl = pathToFileURL(libPath).href;
38+
} else {
39+
fileUrl = libPath;
40+
}
41+
42+
return import(fileUrl).then((mod) => {
3343
const getExePath = mod.default;
3444
return getExePath();
3545
});

0 commit comments

Comments
 (0)