Fix require.cache error when loaded through a typescript file in Node 22.18+#18665
Fix require.cache error when loaded through a typescript file in Node 22.18+#18665thecrypticace merged 7 commits intotailwindlabs:v3from
require.cache error when loaded through a typescript file in Node 22.18+#18665Conversation
|
Sharing here my colleague's @pcaillaudm theory on the root cause:
And indeed, the bug does not trigger when running nodejs 22.18 with the option |
|
Looks like this happens because Node.js loaded a Typescript postcss config file. Your original repo appeared to work fine if the postcss config was named Minimal repro: // file.mjs
import postcss from "postcss";
import config from "./postcss.config.ts";
await postcss(config.plugins).process("");// postcss.config.ts
module.exports = {
plugins: [require("tailwindcss")],
};I'm gonna do a bit more poking around to see what happens when things are required through the typescript loader but this fix/workaround seems reasonable. |
The real issue is that `require.cache` itself is undefined. Also
require.cache error when loaded through a typescript file in Node 22.18+
|
Minimal no Tailwind CSS repro: // test.mjs
import "./file-1.ts";// file-1.ts
require("./file-2.cjs");// file-2.cjs
delete require.cache["foo"];Only happens if the typescript file is loaded via |
|
Thanks! I'll likely tag a v3 release sometime next week. |
This fixes this bug:
Not sure why we end up in this situation. It typically triggers when everything has been cleaned (
rm -rf node_modules && npm ci && npm run build) in my project.EDIT: On our side we have found out that this issue popped up with node 22.18 and was not present in 22.17.