Skip to content

Commit 03b19cb

Browse files
joyeecheungrichardlau
authored andcommitted
bootstrap: improve snapshot unsupported builtin warnings
- Only emit warning when the snapshot is built. In general built-ins loaded after the snapshot is built should work as usual. - Clarify what the warning means PR-URL: #50944 Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 358793e commit 03b19cb

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/internal/main/mksnapshot.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const {
1919
const { isExperimentalSeaWarningNeeded } = internalBinding('sea');
2020

2121
const { emitExperimentalWarning } = require('internal/util');
22-
22+
const { emitWarningSync } = require('internal/process/warning');
2323
const {
2424
getOptionValue,
2525
} = require('internal/options');
@@ -29,6 +29,7 @@ const {
2929
namespace: {
3030
addSerializeCallback,
3131
addDeserializeCallback,
32+
isBuildingSnapshot,
3233
},
3334
} = require('internal/v8/startup_snapshot');
3435

@@ -119,10 +120,18 @@ function requireForUserSnapshot(id) {
119120
err.code = 'MODULE_NOT_FOUND';
120121
throw err;
121122
}
122-
if (!supportedInUserSnapshot(normalizedId)) {
123+
if (isBuildingSnapshot() && !supportedInUserSnapshot(normalizedId)) {
123124
if (!warnedModules.has(normalizedId)) {
124-
process.emitWarning(
125-
`built-in module ${id} is not yet supported in user snapshots`);
125+
// Emit the warning synchronously in case we don't get to process
126+
// the tick and print it before the unsupported built-in causes a
127+
// crash.
128+
emitWarningSync(
129+
`It's not yet fully verified whether built-in module "${id}" ` +
130+
'works in user snapshot builder scripts.\n' +
131+
'It may still work in some cases, but in other cases certain ' +
132+
'run-time states may be out-of-sync after snapshot deserialization.\n' +
133+
'To request support for the module, use the Node.js issue tracker: ' +
134+
'https://github.com/nodejs/node/issues');
126135
warnedModules.add(normalizedId);
127136
}
128137
}

0 commit comments

Comments
 (0)