Skip to content

Commit edc985e

Browse files
GeoffreyBoothaduh95
authored andcommitted
Improve warning
1 parent 42077e5 commit edc985e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/internal/modules/esm/loader.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
require('internal/modules/cjs/loader');
55

66
const {
7+
ArrayPrototypeJoin,
8+
ArrayPrototypeMap,
79
FunctionPrototypeCall,
10+
JSONStringify,
811
ObjectSetPrototypeOf,
912
SafeWeakMap,
1013
} = primordials;
@@ -517,7 +520,11 @@ function createModuleLoader(useCustomLoadersIfPresent = true) {
517520
if (userLoaderPaths.length > 0) {
518521
if (!emittedLoaderFlagWarning) {
519522
process.emitWarning(
520-
'`--experimental-loader` may be removed in the future; instead use `--import` to reference a file that calls `register()`',
523+
'`--experimental-loader` may be removed in the future; instead use `register()`:\n' +
524+
`--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; ${ArrayPrototypeJoin(
525+
ArrayPrototypeMap(userLoaderPaths, (loader) => `register(${JSONStringify(encodeURI(loader))}, pathToFileURL("./"))`),
526+
"; ",
527+
)};'`,
521528
'ExperimentalWarning',
522529
);
523530
emittedLoaderFlagWarning = true;

0 commit comments

Comments
 (0)