Files
node/test/es-module/test-require-module-error-catching.js
Antoine du Hamel 987740399d tools: enforce trailing commas in test/es-module
PR-URL: https://github.com/nodejs/node/pull/60891
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2025-12-03 14:18:40 +01:00

22 lines
519 B
JavaScript

// This tests synchronous errors in ESM from require(esm) can be caught.
'use strict';
require('../common');
const assert = require('assert');
// Runtime errors from throw should be caught.
assert.throws(() => {
require('../fixtures/es-modules/runtime-error-esm.js');
}, {
message: 'hello',
});
// References errors should be caught too.
assert.throws(() => {
require('../fixtures/es-modules/reference-error-esm.js');
}, {
name: 'ReferenceError',
message: 'exports is not defined in ES module scope',
});