Skip to content

Regression when require(extensionless-ts) from JS #324

@webpro

Description

@webpro

Environment

Regression when upgrading from Jiti v1 to Jiti v2.

Can reproduce in Node.js 18 and 22.

Reproduction

See https://stackblitz.com/edit/stackblitz-starters-earn9d

Initially you can ignore client and shared folders, that holds the original dependency chain in the freeCodeCamp repo where Knip is used and gatsby-node.js is loaded with jiti.import (Jiti v2). I minimized that chain for a minimal repro to just two files: index.js and req-ts.ts.

Can see the issue here (require(extensionless-ts)) and maybe it wasn't supposed to work in the first place, but this loads without issues in Jiti v1:

$ npx jiti@^1 index.js

Yet with v2 this gives an error:

$ npx jiti@^2 index.js
Error: Cannot find module './req-ts'
Require stack:
- /Users/lars/p/knip/jiti-repro/index.js

Describe the bug

With Jiti v1, Knip was loading this file without issues using the jitiCJS loader as created here: https://github.com/webpro-nl/knip/blob/b1cf45a9c82f16e83618e7841c2ec850d9b9d781/packages/knip/src/util/jiti.ts#L8-L21 (i.e. esmResolve: false, extensions: [] and interopDefault: true).

I think it's a regression, but maybe I'm missing some config.

Additional context

Didn't yet look into how in the original context Gatsby loads this, first wanted to check whether Jiti v2 is supposed to support this at all in the first place, or whether it's considered a breaking change.

Logs

No response

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