-
Notifications
You must be signed in to change notification settings - Fork 63
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
Jiti handles imports incorrectly in Node 22.12+ after a require(esm)
call fails
#346
Comments
Thanks for the report and reproduction. I can confirm behavior change. Will investigate to find a workaround to this (my guess is require-cache). BTW are you aware that jiti itself always tries native import before fallback? (this means by upgrading to jiti v2 you can remove try/catch altogether) |
Update: I also can confirm the issue happens because Node.js require-cache will become half broken in the first Current workaround is using |
I prepared a solution however not sure if it is safe or better to ask Node.js fix it upstream.. #348 |
Environment
OS: macOS 15.2
Node: v22.12.0
NPM: v10.9.0
Reproduction
https://github.com/thecrypticace/node-22-jiti-bug
Describe the bug
Node 22.12 backported
require(esm)
support and it appears there's a bug either in Node or in Jiti that's causing imported files to be handled incorrectly.This bug reproduces under the following conditions:
require(esm)
call is usedtry/catch
blockThe imports inside that file may not return correct results. In this case a function is being returned as an empty object.
When Jiti is used by itself the bug does not happen — only in conjunction with a failed
require(esm)
call. The one in this repo fails because its importing a file without using a file extension:If you add the file extension, the bug does not happen because the
require(esm)
call works:Additional context
I'm one of the maintainer's for Tailwind CSS and several users have reported plugins not working in Tailwind CSS v3.x with the latest versions of Node.js. I tracked this down to a function being turned into an object — likely because of an issue with import handling.
This bug appears to affect:
Logs
The text was updated successfully, but these errors were encountered: