Skip to content
This repository was archived by the owner on Apr 16, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/internal/modules/esm/default_resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ function resolve(specifier, parentURL) {
}
}
}

if (!format) {
if (isMain)
if (isMain && asyncESM.typeFlag)
format = asyncESM.typeFlag;
else if (isMain)
format = type === 2 ? 'module' : 'commonjs';
else
throw new ERR_UNKNOWN_FILE_EXTENSION(fileURLToPath(url),
fileURLToPath(parentURL));
}

return { url: `${url}`, format };
}

Expand Down
32 changes: 32 additions & 0 deletions test/es-module/test-esm-no-extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

const common = require('../common');
const fixtures = require('../common/fixtures');
const { spawn } = require('child_process');
const assert = require('assert');

const entry = fixtures.path('/es-modules/noext-esm');

const child = spawn(process.execPath, [
'--experimental-modules',
'--type=module',
entry
]);

let stderr = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', (data) => {
stderr += data;
});
let stdout = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
stdout += data;
});
child.on('close', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
assert.strictEqual(stdout, 'executed\n');
assert.strictEqual(stderr, `(node:${child.pid}) ` +
'ExperimentalWarning: The ESM module loader is experimental.\n');
}));
2 changes: 2 additions & 0 deletions test/fixtures/es-modules/noext-esm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default 'module';
console.log('executed');