diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 9773c4069f61c6..41070fe145c25e 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2451,14 +2451,18 @@ instead. ### DEP0130: Module.createRequireFromPath() -Type: Documentation-only +Type: Runtime -Module.createRequireFromPath() is deprecated. Please use [`module.createRequire()`][] instead. +Module.createRequireFromPath() is deprecated. Please use +[`module.createRequire()`][] instead. ### DEP0131: Legacy HTTP parser diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index e676d06fa91456..27f8c8912a9ef1 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -860,7 +860,12 @@ function createRequireFromPath(filename) { return makeRequireFunction(m); } -Module.createRequireFromPath = createRequireFromPath; +Module.createRequireFromPath = deprecate( + createRequireFromPath, + 'Module.createRequireFromPath() is deprecated. ' + + 'Use Module.createRequire() instead.', + 'DEP0130' +); const createRequireError = 'must be a file URL object, file URL string, or ' + 'absolute path string'; diff --git a/test/message/async_error_sync_esm.out b/test/message/async_error_sync_esm.out index f34628ef44e52a..544916e24866e2 100644 --- a/test/message/async_error_sync_esm.out +++ b/test/message/async_error_sync_esm.out @@ -5,3 +5,4 @@ Error: test at async three (*fixtures*async-error.js:20:3) at async four (*fixtures*async-error.js:24:3) at async main (*message*async_error_sync_esm.mjs:7:5) +(node:*) [DEP0130] DeprecationWarning: Module.createRequireFromPath() is deprecated. Use Module.createRequire() instead.