Open pqnet opened 10 months ago
Workaround for Fastify: require.cache
can be polyfilled with
if (typeof require !== 'undefined' && typeof require.cache === 'undefined') {
require.cache = {}
}
For Fastify or other that can also be achieved:
const { createRequire } = require('node:module'); require = createRequire(__filename);
See: https://nodejs.org/api/single-executable-applications.html#requireid-in-the-injected-main-script-is-not-file-based
Version
v20.4.0 v20.5.1 v20.3.0
Platform
Linux 5.15.90.1-microsoft-standard-WSL2
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Always reproducible
What is the expected behavior? Why is that the expected behavior?
require.cache
should be an object as of https://nodejs.org/api/modules.html#requirecacheWhat do you see instead?
require.cache
is undefined. Trying to index it or enumerate it withObject.entries
will result in TypeErrorAdditional information
This is relevant for Fastify which uses cache to provide a printable name for a plugin (based on its file path). See https://github.com/fastify/fastify/blob/c235d2dc136a67c51095f188742c743d8cb32839/lib/pluginUtils.js#L27