Skip to content

Commit

Permalink
fix: dynamic imports on windows require file scheme (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Dec 4, 2023
1 parent c03d8f4 commit 54eb338
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/req.js
@@ -1,5 +1,6 @@
// @ts-check
const { createRequire } = require('node:module')
const { pathToFileURL } = require('node:url')

const TS_EXT_RE = /\.(c|m)?ts$/

Expand All @@ -16,7 +17,7 @@ async function req(name, rootFile = __filename) {
let url = __require.resolve(name)

try {
return (await import(url)).default
return (await import(pathToFileURL(url).href)).default
} catch (err) {
if (!TS_EXT_RE.test(url)) {
/* c8 ignore start */
Expand Down

0 comments on commit 54eb338

Please sign in to comment.