Skip to content

Commit 5a835e1

Browse files
support NODE_PATH in standalone build (#19617)
References #19391. References #16274. Right now, when using the standalone build of the TailwindCSS CLI, you cannot use a custom `NODE_PATH`, but you can when using it via Node.js directly. A custom NODE_PATH allows you to resolve imports from multiple locations. For example, in [Phoenix LiveView](https://github.com/phoenixframework/phoenix_live_view/), we have a feature where you can write scripts in templates that we extract at compile time to a custom folder and users can import those in their application bundle by saying ```javascript import { hooks as colocatedHooks } from "phoenix-colocated/my_app" ``` where the "phoenix-colocated" folder lives in a different location than the usual `node_modules` folder. This works fine with the default esbuild setup, as it respects `NODE_PATH`, so we can pass it a custom location. We want to also support colocating CSS in templates soon, but the same approach doesn't work with the standalone Tailwind CLI we ship with default Phoenix projects. It works when running Tailwind through Node.js, but we don't want to tell users they need to install it, just to use the feature. This patch changes the lookup logic for the standalone CLI to also account for `NODE_PATH`. Note that you can pass multiple paths, that are split according the the OS PATH separator. --------- Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
1 parent aad6017 commit 5a835e1

File tree

3 files changed

+2
-4
lines changed

3 files changed

+2
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
- Canonicalization: move the `-` sign inside the arbitrary value `-left-[9rem]``left-[-9rem]` ([#19858](https://github.com/tailwindlabs/tailwindcss/pull/19858))
3434
- Canonicalization: move the `-` sign outside the arbitrary value `ml-[calc(-1*var(--width))]``-ml-(--width)` ([#19858](https://github.com/tailwindlabs/tailwindcss/pull/19858))
3535
- Improve performance when scanning JSONL / NDJSON files ([#19862](https://github.com/tailwindlabs/tailwindcss/pull/19862))
36+
- Support `NODE_PATH` environment variable in standalone build ([#19617](https://github.com/tailwindlabs/tailwindcss/pull/19617))
3637

3738
## [4.2.2] - 2026-03-18
3839

packages/@tailwindcss-node/src/compile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ async function importModule(path: string): Promise<any> {
194194
}
195195
}
196196

197-
const modules = ['node_modules', ...(process.env.NODE_PATH ? [process.env.NODE_PATH] : [])]
197+
const modules = ['node_modules', ...(process.env.NODE_PATH ? [...process.env.NODE_PATH.split(path.delimiter)] : [])]
198198

199199
const cssResolver = EnhancedResolve.ResolverFactory.createResolver({
200200
fileSystem: new EnhancedResolve.CachedInputFileSystem(fs, 4000),

packages/@tailwindcss-standalone/scripts/build.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ for (let { target, name } of builds) {
6060

6161
// This simplifies the Oxide loading code a small amount
6262
'process.env.NAPI_RS_NATIVE_LIBRARY_PATH': JSON.stringify(''),
63-
64-
// No need to support additional NODE_PATHs in the standalone build
65-
'process.env.NODE_PATH': JSON.stringify(''),
6663
},
6764

6865
compile: {

0 commit comments

Comments
 (0)