Skip to content

Commit

Permalink
fix: lazy createRequire to allow exceptions being catched, fixes #497
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Apr 19, 2022
1 parent ecc04c9 commit b377dad
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/fs/node-require.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { createRequire } from 'module'

const require = createRequire(import.meta.url)

export const requireResolve = require.resolve
export function requireResolve (file) {
/**
* createRequire() can throw,
* when import.meta.url not begin with "file://".
*/
const require = createRequire(import.meta.url)
return require.resolve(file)
}

0 comments on commit b377dad

Please sign in to comment.