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 || {})); }