Skip to content

Commit a61d26a

Browse files
AllieJonssonAlfred Jonsson
and
Alfred Jonsson
authoredMay 14, 2024
fix: path to file url (#1372)
Co-authored-by: Alfred Jonsson <alfred.jonsson@decerno.se>
1 parent d3ddbdd commit a61d26a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed
 

‎packages/core/src/utils/dynamic-import.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { pathToFileURL } from 'url';
12
import { isModule, isObject, isString } from './assertion';
23
import { resolve } from './path';
34

@@ -13,7 +14,10 @@ export const dynamicImport = async <T>(
1314
try {
1415
if (isString(toImport)) {
1516
const path = resolve(from, toImport);
16-
const data = await import(path);
17+
// use pathToFileURL to solve issue #1332.
18+
// https://github.com/nodejs/node/issues/31710
19+
const fileUrl = pathToFileURL(path);
20+
const data = await import(fileUrl.href);
1721
if (takeDefault && (isObject(data) || isModule(data)) && data.default) {
1822
return (data as any).default as T;
1923
}

0 commit comments

Comments
 (0)
Please sign in to comment.