Skip to content

Commit

Permalink
Fixed ES module loading on Windows
Browse files Browse the repository at this point in the history
* Fixes #169
  • Loading branch information
sgravrock committed Oct 29, 2020
1 parent 2571c27 commit abe4f13
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ function Loader(options) {

Loader.prototype.load = function(path) {
if (path.endsWith('.mjs')) {
return this.import_(path).catch(function(e) {
// The ES module spec requires import paths to be valid URLs. As of v14,
// Node enforces this on Windows but not on other OSes.
const url = `file://${path}`;
return this.import_(url).catch(function(e) {
if (e.message.indexOf(path) !== -1 || e.stack.indexOf(path) !== -1) {
return Promise.reject(e);
} else {
Expand Down
2 changes: 1 addition & 1 deletion spec/loader_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('loader', function() {
const loaderPromise = loader.load('./foo/bar/baz.mjs');

expect(requireShim).not.toHaveBeenCalled();
expect(importShim).toHaveBeenCalledWith('./foo/bar/baz.mjs');
expect(importShim).toHaveBeenCalledWith('file://./foo/bar/baz.mjs');
await expectAsync(loaderPromise).toBePending();

resolve();
Expand Down

0 comments on commit abe4f13

Please sign in to comment.