Skip to content

Commit

Permalink
Fix ESM imports on Windows (nightwatchjs#3585)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchevsky authored and harshit-bs committed Mar 16, 2023
1 parent 370c1ec commit f2cd5fc
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 f2cd5fc

Please sign in to comment.