Skip to content

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

Merged
hi-ogawa merged 1 commit intovitejs:mainfrom
sapphi-red:test/fix-dont-use-__dirname-in-tailwind-config
Dec 16, 2024
Merged

test: don't use __dirname in tailwind config#18969
hi-ogawa merged 1 commit intovitejs:mainfrom
sapphi-red:test/fix-dont-use-__dirname-in-tailwind-config

Conversation

@sapphi-red
Copy link
Copy Markdown
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 vitejs/rolldown-vite that referenced this pull request Dec 16, 2024
@hi-ogawa
Copy link
Copy Markdown
Contributor

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

@sapphi-red
Copy link
Copy Markdown
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
Copy Markdown
Contributor

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
@sapphi-red sapphi-red deleted the test/fix-dont-use-__dirname-in-tailwind-config branch December 16, 2024 05:53
moonlitusun pushed a commit to moonlitusun/vite that referenced this pull request May 25, 2025
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