jiti icon indicating copy to clipboard operation
jiti copied to clipboard

Importing ts file with `.js` specifier from `.mjs` in another workspace fails

Open webpro opened this issue 1 year ago • 1 comments

Environment

Node.js v20, both jiti v1 + v2

Reproduction

Please see https://stackblitz.com/edit/stackblitz-starters-zwqrgl?file=playwright.config.mjs

npx jiti playwright.config.mjs 

Issue happens in both jiti v1 and v2. Cannot find module, but should print { hello: 1 }

First I'd like to know if you think this should even work. If so, I'm happy to look into fix & send PR.

Describe the bug

Not sure if this is even supposed to work: import with .js extensions in specifier which is actually a .ts file and in a workspace dir with type: "module". Relevant bits (minimized in repro):

  • https://github.com/argos-ci/argos/blob/main/playwright.config.mjs
  • https://github.com/argos-ci/argos/blob/main/apps/backend/src/config/index.ts
  • https://github.com/argos-ci/argos/blob/main/apps/backend/package.json#L5

Apparently Playwright's using something that's able to load it all up.

Additional context

No response

Logs

No response

webpro avatar Oct 22 '24 17:10 webpro

Thanks for repro. Quickly checking with JITI_DEBUG=1, first fail is normal (natively this is an anti-spec). But in fallback mode, it looks strange that the ts extension could not be find seems worth to investigate.

image

pi0 avatar Oct 24 '24 06:10 pi0