Skip to content

Take NODE_PATH into account when resolving modules#16274

Merged
philipp-spiess merged 2 commits into
mainfrom
fix/node-path-env
Feb 5, 2025
Merged

Take NODE_PATH into account when resolving modules#16274
philipp-spiess merged 2 commits into
mainfrom
fix/node-path-env

Conversation

@philipp-spiess

@philipp-spiess philipp-spiess commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

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

@philipp-spiess philipp-spiess requested a review from a team as a code owner February 5, 2025 12:00

@RobinMalfait RobinMalfait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! Can you add a changelog entry?

@philipp-spiess

Copy link
Copy Markdown
Contributor Author

Can you add a changelog entry?

Yes sir this is indeed part of my set of abilities.

@SteffenDE

Copy link
Copy Markdown
Contributor

It looks like this does not work in the standalone CLI, is that expected?

$ NODE_PATH=_build/dev/ npx @tailwindcss/cli --cwd assets/ --config tailwind.config.js -i css/app.css --output ../priv/static/assets/app.css
≈ tailwindcss v4.1.7

Done in 32ms

vs

$ NODE_PATH=_build/dev/ ~/Downloads/tailwindcss-macos-arm64 --cwd assets/ --config tailwind.config.js -i css/app.css --output ../priv/static/assets/app.css
≈ tailwindcss v4.1.7

Error: Can't resolve 'colocated_svgs/index.css' in '/Users/steffen/oss/colocated_demo/assets/css'

SteffenDE added a commit to SteffenDE/tailwindcss that referenced this pull request Jan 29, 2026
also allows to pass a path with separator

References tailwindlabs#19391.
References tailwindlabs#16274.
RobinMalfait added a commit that referenced this pull request Apr 17, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[V4] new import style doesn't work for node_modules in non-standard location (e.g. gradle)

3 participants