Skip to content

Jiti handles imports incorrectly in Node 22.12+ after a require(esm) call fails #346

@thecrypticace

Description

@thecrypticace

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:

  • A require(esm) call is used
  • That call fails and is caught by a try/catch block
  • Jiti is then used to import that same file

The 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:

import file from "./file";

If you add the file extension, the bug does not happen because the require(esm) call works:

import file from "./file.js";

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:

  • Node v22.12+
  • Node v23.0+
  • macOS / Windows (haven't tested Linux but probably the same)
  • Jiti 2's sync and async methods for importing files are both affected
  • Jiti 1 is also affected (this is what we use in Tailwind CSS v3 currently)

Logs

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions