You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Module hooks' context.importAttributes is undefined for require(), but documented as an <Object> #67209
Both hooks document context.importAttributes as an <Object>, but for a module that require() loads it's undefined. That looks deliberate: the CommonJS loader passes /* importAttributes */ undefined to the hooks (resolve, load, load), and customization_hooks.js types it ImportAttributes|undefined.
So a hook written from the docs, e.g. context.importAttributes.type === "json", throws as soon as anything is require()d, which in practice means as soon as a CommonJS dependency loads. @types/node follows the docs too (importAttributes: ImportAttributes), so TypeScript doesn't catch it either.
On v26.13.0, logging it from registerHooks() for require() and import() of the same kinds of files:
With a.cjs (module.exports = 1;), b.mjs (export default 2;) and c.json ({"c":3}) next to it: node --import ./hooks.mjs main.cjs.
Either documenting it as <Object> | <undefined> (undefined for require()), or passing {} there, as import() without attributes already gets, would fix it. If it's meant to stay undefined, documenting that is enough, and @types/node can follow.
Activity