Skip to content

module: runtime deprecate require.extensions #58642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ changes:
description: Documentation-only deprecation.
-->

Type: Documentation-only
Type: Runtime

The [`require.extensions`][] property is deprecated.
Copy link
Member

@legendecas legendecas Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an alternative, like module.register or module.registerHooks, should be recommended, and be stable, before runtime deprecating this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registerHooks, not register. The latter should go away once the former is ready. And registerHooks is a more appropriate replacement for extensions as both are sync.

Copy link
Member Author

@marco-ippolito marco-ippolito Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would actually need an api that returns all the registered hooks + registerHooks


Expand Down
15 changes: 13 additions & 2 deletions lib/internal/modules/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const { pathToFileURL, fileURLToPath } = require('internal/url');
const assert = require('internal/assert');

const { getOptionValue } = require('internal/options');
const { setOwnProperty, getLazy } = require('internal/util');
const { setOwnProperty, getLazy, deprecate } = require('internal/util');
const { inspect } = require('internal/util/inspect');

const lazyTmpdir = getLazy(() => require('os').tmpdir());
Expand Down Expand Up @@ -160,8 +160,19 @@ function makeRequireFunction(mod) {

setOwnProperty(require, 'main', process.mainModule);

let extensions = Module._extensions;
// Enable support to add extra extension types.
require.extensions = Module._extensions;
ObjectDefineProperty(require, 'extensions', {
__proto__: null,
get: deprecate(() => {
return extensions;
}, 'require.extensions is deprecated', 'DEP0039'),
set: deprecate((value) => {
extensions = value;
}, 'require.extensions is deprecated', 'DEP0039'),
configurable: true,
enumerable: true,
});

require.cache = Module._cache;

Expand Down