From 54dcf39b0557e6d8ca5271fd2706bb69e058b9e6 Mon Sep 17 00:00:00 2001 From: Nick Chevsky Date: Sun, 29 Jan 2023 14:43:00 -0600 Subject: [PATCH] Fix ESM imports on Windows (#3585) --- lib/utils/requireModule.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/utils/requireModule.js b/lib/utils/requireModule.js index aa7c1e15b5..f65315e8d4 100644 --- a/lib/utils/requireModule.js +++ b/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 { @@ -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 || {})); }