Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: don't use __dirname in tailwind config #18969

Conversation

sapphi-red
Copy link
Member

Description

require(esm) is now enabled by default from Node 22.12.0.
Before node 22.12.0, the tailwind config was loaded by jiti and that allowed users to use __dirname in ESM tailwind configs.
But after node 22.12.0, require(esm) is supported by Node and that is used instead of jiti and thus __dirname is not declared and errors.

https://github.com/tailwindlabs/tailwindcss/blob/f875ab9706cae8262e15e5b382580fc8e2d4197f/src/lib/load-config.ts#L34-L51

@sapphi-red sapphi-red added the p1-chore Doesn't change code behavior (priority) label Dec 16, 2024
sapphi-red added a commit to rolldown/vite that referenced this pull request Dec 16, 2024
@hi-ogawa
Copy link
Collaborator

How does node 18, 20 work (before and after this PR)? Is it still go to lazyJiti fallback in L50?

@sapphi-red
Copy link
Member Author

On node 18 / 20, before this PR, require throws ERR_REQUIRE_ESM error, so lazyJiti will be called and uses sucrase for the transform. After this PR, require still throws ERR_REQUIRE_ESM error and lazyJiti will be called, but babel will be used for the transform.

@hi-ogawa
Copy link
Collaborator

Testing locally, I'm not sure what's happening with require(esm) error and try/catch. It looks try/catch is called but still unhandle errors somewhere?

@hi-ogawa hi-ogawa merged commit 30f256e into vitejs:main Dec 16, 2024
16 checks passed
@sapphi-red sapphi-red deleted the test/fix-dont-use-__dirname-in-tailwind-config branch December 16, 2024 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p1-chore Doesn't change code behavior (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants