From a3a16e64d28c149aab3d4df67a64648627d0ea62 Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Wed, 4 Sep 2024 19:43:18 +0200 Subject: [PATCH] Fix a crash with older Node.js versions (#14342) Closes #14341 --------- Co-authored-by: Jordan Pittman --- CHANGELOG.md | 1 + packages/@tailwindcss-node/src/index.cts | 6 +++++- packages/@tailwindcss-node/src/index.ts | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8d05d228..8c6bf3eb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Evaluate theme functions in plugins and JS config files ([#14326](https://github.com/tailwindlabs/tailwindcss/pull/14326)) - Ensure theme values overridden with `reference` values don't generate stale CSS variables ([#14327](https://github.com/tailwindlabs/tailwindcss/pull/14327)) - Don’t suggest named opacity modifiers in intellisense ([#14339](https://github.com/tailwindlabs/tailwindcss/pull/14339)) +- Fix a crash with older Node.js versions ([#14342](https://github.com/tailwindlabs/tailwindcss/pull/14342)) ## [4.0.0-alpha.21] - 2024-09-02 diff --git a/packages/@tailwindcss-node/src/index.cts b/packages/@tailwindcss-node/src/index.cts index bb1fabe85..a143865ef 100644 --- a/packages/@tailwindcss-node/src/index.cts +++ b/packages/@tailwindcss-node/src/index.cts @@ -5,5 +5,9 @@ export * from './compile' // In Bun, ESM modules will also populate `require.cache`, so the module hook is // not necessary. if (!process.versions.bun) { - Module.register(pathToFileURL(require.resolve('@tailwindcss/node/esm-cache-loader'))) + // `Module#register` was added in Node v18.19.0 and v20.6.0 + // + // Not calling it means that while ESM dependencies don't get reloaded, the + // actual included files will because they cache bust directly via `?id=…` + Module.register?.(pathToFileURL(require.resolve('@tailwindcss/node/esm-cache-loader'))) } diff --git a/packages/@tailwindcss-node/src/index.ts b/packages/@tailwindcss-node/src/index.ts index 2fcbfa89b..85b292ed0 100644 --- a/packages/@tailwindcss-node/src/index.ts +++ b/packages/@tailwindcss-node/src/index.ts @@ -6,5 +6,10 @@ export * from './compile' // not necessary. if (!process.versions.bun) { let localRequire = Module.createRequire(import.meta.url) - Module.register(pathToFileURL(localRequire.resolve('@tailwindcss/node/esm-cache-loader'))) + + // `Module#register` was added in Node v18.19.0 and v20.6.0 + // + // Not calling it means that while ESM dependencies don't get reloaded, the + // actual included files will because they cache bust directly via `?id=…` + Module.register?.(pathToFileURL(localRequire.resolve('@tailwindcss/node/esm-cache-loader'))) }