Skip to content

Commit

Permalink
Fix ESM imports on Windows (#3585)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchevsky committed Jan 29, 2023
1 parent cefae71 commit 54dcf39
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/utils/requireModule.js
@@ -1,3 +1,9 @@
const getNodeVersion = () => {
const version = process.version.replace('v', '');

return parseInt(version, 10);
}

module.exports = function (fullpath) {
let exported;
try {
Expand All @@ -15,6 +21,12 @@ module.exports = function (fullpath) {
throw err;
}

if (getNodeVersion() >= 14) {
const {pathToFileURL} = require('node:url');

return import(pathToFileURL(fullpath).href).then(result => (result.default || {}));
}

return import(fullpath).then(result => (result.default || {}));
}

Expand Down

0 comments on commit 54dcf39

Please sign in to comment.