diff --git a/src/cjs/api/module-extensions.ts b/src/cjs/api/module-extensions.ts index 4512a2568..30edd110c 100644 --- a/src/cjs/api/module-extensions.ts +++ b/src/cjs/api/module-extensions.ts @@ -120,6 +120,7 @@ export const createExtensions = ( * If not, only expose if it's not namespaced */ enumerable: descriptor?.enumerable || !namespace, + writable: true, }); } diff --git a/tests/specs/api.ts b/tests/specs/api.ts index 83b5133bd..afac49a70 100644 --- a/tests/specs/api.ts +++ b/tests/specs/api.ts @@ -79,6 +79,21 @@ export default testSuite(({ describe }, node: NodeApis) => { expect(stdout).toContain('index.ts:3:22'); }); + test('loader overwritable from Module', async () => { + await using fixture = await createFixture({ + 'index.mjs': ` + import Module from 'node:module'; + const _require = Module.createRequire(import.meta.url); + _require.extensions['.ts'] = () => {}; + `, + }); + + await execaNode(fixture.getPath('index.mjs'), { + nodePath: node.path, + nodeOptions: ['--require', tsxCjsPath], + }); + }); + test('register / unregister', async () => { await using fixture = await createFixture({ 'register.cjs': `