MCPcopy Create free account
hub / github.com/nodejs/node / requireForUserSnapshot

Function requireForUserSnapshot

lib/internal/main/mksnapshot.js:103–130  ·  view source on GitHub ↗
(id)

Source from the content-addressed store, hash-verified

101}
102
103function requireForUserSnapshot(id) {
104 const normalizedId = normalizeRequirableId(id);
105 if (!normalizedId) {
106 // eslint-disable-next-line no-restricted-syntax
107 const err = new Error(
108 `Cannot find module '${id}'. `,
109 );
110 err.code = 'MODULE_NOT_FOUND';
111 throw err;
112 }
113 if (isBuildingSnapshot() && !supportedInUserSnapshot(normalizedId)) {
114 if (!warnedModules.has(normalizedId)) {
115 // Emit the warning synchronously in case we don't get to process
116 // the tick and print it before the unsupported built-in causes a
117 // crash.
118 emitWarningSync(
119 `It's not yet fully verified whether built-in module "${id}" ` +
120 'works in user snapshot builder scripts.\n' +
121 'It may still work in some cases, but in other cases certain ' +
122 'run-time states may be out-of-sync after snapshot deserialization.\n' +
123 'To request support for the module, use the Node.js issue tracker: ' +
124 'https://github.com/nodejs/node/issues');
125 warnedModules.add(normalizedId);
126 }
127 }
128
129 return require(normalizedId);
130}
131
132
133function main() {

Callers

nothing calls this directly

Calls 6

isBuildingSnapshotFunction · 0.85
supportedInUserSnapshotFunction · 0.85
emitWarningSyncFunction · 0.85
hasMethod · 0.65
addMethod · 0.65
requireFunction · 0.50

Tested by

no test coverage detected