diff --git a/bin/main.js b/bin/main.js index 3c6585776f..76fa6c0783 100644 --- a/bin/main.js +++ b/bin/main.js @@ -180,7 +180,7 @@ export async function main(nodeProcess) { // try require for json markedConfig = require(configFile); } catch(err) { - if (err.code !== 'ERR_REQUIRE_ESM') { + if (err.code !== 'ERR_REQUIRE_ESM' && err.code !== 'ERR_REQUIRE_ASYNC_MODULE') { throw err; } // must import esm diff --git a/test/unit/bin.test.js b/test/unit/bin.test.js index 30fa726674..e0b2bf718b 100644 --- a/test/unit/bin.test.js +++ b/test/unit/bin.test.js @@ -116,6 +116,11 @@ describe('bin/marked', () => { stdout: '

line1
line2

', })); + it('config with top-level await', testInput({ + args: ['--config', fixturePath('bin-config-await.mjs'), '-s', 'line1\nline2'], + stdout: '

line1
line2

', + })); + it('config not found', testInput({ args: ['--config', fixturePath('does-not-exist.js'), '-s', 'line1\nline2'], stderr: `Cannot load config file '${fixturePath('does-not-exist.js')}'`, diff --git a/test/unit/fixtures/bin-config-await.mjs b/test/unit/fixtures/bin-config-await.mjs new file mode 100644 index 0000000000..00291ad103 --- /dev/null +++ b/test/unit/fixtures/bin-config-await.mjs @@ -0,0 +1,3 @@ +export default await Promise.resolve({ + breaks: true, +});