Thanks to visit codestin.com
Credit goes to github.com

Skip to content

jiti v2.5.0 fails to import CommonJS module that exports a Promise #388

@fasttime

Description

@fasttime

Environment

The jiti version is 2.5.0.

Noticed in a Ubuntu VM running Node.js 24.4.1, but I can reproduce it in older versions, too.

Reproduction

A minimal repro:

// index.mjs
import { createJiti } from 'jiti';

const jiti = createJiti(import.meta.filename);
const ctsFileURL = new URL('./file.cts', import.meta.url);
await jiti.import(ctsFileURL.href);
// file.cts
export = Promise.resolve({});

Running node ./index.mjs prints:

TypeError: Method Promise.prototype.then called on incompatible receiver #<Promise>

Also a StackBlitz repro: https://stackblitz.com/edit/hffiw6dx

Describe the bug

It seems that a recent change in jiti v2.5.0 is causing an error when a CommonJS module that export a Promise is imported.

Additional context

We noticed that jiti v2.5.0 is causing CI failures in the ESLint repo, for example: https://github.com/eslint/eslint/actions/runs/16488422115/job/46617784304.

Logs

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