GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — module: trim off internal stack frames for require(esm) warnings · nodejs/node@fdf5028

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • modules/cjs
      • loader.js
    • util.js
  • test
    • es-module
      • test-require-module-warning.js
    • fixtures/es-modules
      • require-module.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/modules/cjs/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,10 @@ function loadESMFromCJS(mod, filename) {
13601360
messagePrefix = `${from} is loading ES Module ${to} using require().\n`;
13611361
}
13621362
}
1363-
emitExperimentalWarning('Support for loading ES Module in require()', messagePrefix);
1363+
emitExperimentalWarning('Support for loading ES Module in require()',
1364+
messagePrefix,
1365+
undefined,
1366+
parent?.require);
13641367
const {
13651368
wrap,
13661369
namespace,
Collapse file

‎lib/internal/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/util.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,20 @@ function slowCases(enc) {
255255
}
256256
}
257257

258-
function emitExperimentalWarning(feature, messagePrefix) {
258+
/**
259+
* @param {string} feature Feature name used in the warning message
260+
* @param {string} messagePrefix Prefix of the warning message
261+
* @param {string} code See documentation of process.emitWarning
262+
* @param {string} ctor See documentation of process.emitWarning
263+
*/
264+
function emitExperimentalWarning(feature, messagePrefix, code, ctor) {
259265
if (experimentalWarnings.has(feature)) return;
260266
experimentalWarnings.add(feature);
261267
let msg = `${feature} is an experimental feature and might change at any time`;
262268
if (messagePrefix) {
263269
msg = messagePrefix + msg;
264270
}
265-
process.emitWarning(msg, 'ExperimentalWarning');
271+
process.emitWarning(msg, 'ExperimentalWarning', code, ctor);
266272
}
267273

268274
function filterDuplicateStrings(items, low) {
Collapse file

‎test/es-module/test-require-module-warning.js‎

Copy file name to clipboard
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
// This checks the warning and the stack trace emitted by the require(esm)
4+
// experimental warning. It can get removed when `require(esm)` becomes stable.
5+
6+
require('../common');
7+
const { spawnSyncAndAssert } = require('../common/child_process');
8+
const fixtures = require('../common/fixtures');
9+
const assert = require('assert');
10+
11+
spawnSyncAndAssert(process.execPath, [
12+
'--trace-warnings',
13+
fixtures.path('es-modules', 'require-module.js'),
14+
], {
15+
trim: true,
16+
stderr(output) {
17+
const lines = output.split('\n');
18+
assert.match(
19+
lines[0],
20+
/ExperimentalWarning: CommonJS module .*require-module\.js is loading ES Module .*message\.mjs/
21+
);
22+
assert.strictEqual(
23+
lines[1],
24+
'Support for loading ES Module in require() is an experimental feature and might change at any time'
25+
);
26+
assert.match(
27+
lines[2],
28+
/at require \(.*modules\/helpers:\d+:\d+\)/
29+
);
30+
assert.match(
31+
lines[3],
32+
/at Object\.<anonymous> \(.*require-module\.js:1:1\)/
33+
);
34+
}
35+
});
Collapse file

‎test/fixtures/es-modules/require-module.js‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./message.mjs');

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.