From 3f8e7647b6a47b944b363ab4af2a8cddd30d2e4a Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Wed, 5 Feb 2025 16:21:31 +0100 Subject: [PATCH] Take `NODE_PATH` into account when resolving modules (#16274) Fixes #15847 This PR changes the node specific resolver config to takes the eventual `NODE_PATH` env into account. ## Test plan See #15847 Screenshot 2025-02-05 at 12 58 20 --- CHANGELOG.md | 1 + packages/@tailwindcss-node/src/compile.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab3333224cc9..5e5da5ad741a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix missing `@keyframes` definition ([#16237](https://github.com/tailwindlabs/tailwindcss/pull/16237)) - Vite: Skip parsing stylesheets with the `?commonjs-proxy` flag ([#16238](https://github.com/tailwindlabs/tailwindcss/pull/16238)) - Fix `order-first` and `order-last` for Firefox ([#16266](https://github.com/tailwindlabs/tailwindcss/pull/16266)) +- Ensure `NODE_PATH` is respected when resolving JavaScript and CSS files ([#16274](https://github.com/tailwindlabs/tailwindcss/pull/16274)) ## [4.0.3] - 2025-02-01 diff --git a/packages/@tailwindcss-node/src/compile.ts b/packages/@tailwindcss-node/src/compile.ts index b946c79defd2..9f11f1d5a91c 100644 --- a/packages/@tailwindcss-node/src/compile.ts +++ b/packages/@tailwindcss-node/src/compile.ts @@ -193,12 +193,15 @@ async function importModule(path: string): Promise { } } +const modules = ['node_modules', ...(process.env.NODE_PATH ? [process.env.NODE_PATH] : [])] + const cssResolver = EnhancedResolve.ResolverFactory.createResolver({ fileSystem: new EnhancedResolve.CachedInputFileSystem(fs, 4000), useSyncFileSystemCalls: true, extensions: ['.css'], mainFields: ['style'], conditionNames: ['style'], + modules, }) async function resolveCssId( id: string, @@ -227,6 +230,7 @@ const esmResolver = EnhancedResolve.ResolverFactory.createResolver({ useSyncFileSystemCalls: true, extensions: ['.js', '.json', '.node', '.ts'], conditionNames: ['node', 'import'], + modules, }) const cjsResolver = EnhancedResolve.ResolverFactory.createResolver({ @@ -234,6 +238,7 @@ const cjsResolver = EnhancedResolve.ResolverFactory.createResolver({ useSyncFileSystemCalls: true, extensions: ['.js', '.json', '.node', '.ts'], conditionNames: ['node', 'require'], + modules, }) async function resolveJsId(