fix: use createRequire for ESM, fixes #334

This commit is contained in:
Harttle
2022-04-18 00:43:17 +08:00
parent c7216c6358
commit eec381ec72
13 changed files with 89 additions and 4 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
import * as _ from '../util/underscore'
import { sep, resolve as nodeResolve, extname, dirname as nodeDirname } from 'path'
import { stat, statSync, readFile as nodeReadFile, readFileSync as nodeReadFileSync } from 'fs'
import { requireResolve } from './node-require'
const statAsync = _.promisify(stat)
const readFileAsync = _.promisify<string, string, string>(nodeReadFile)
@@ -33,7 +34,7 @@ export function resolve (root: string, file: string, ext: string) {
}
export function fallback (file: string) {
try {
return require.resolve(file)
return requireResolve(file)
} catch (e) {}
}
export function dirname (filepath: string) {