unjs/unimport

`scanImportsFromDir` fails to detect `subdir/index.{tsx|jsx}` files

Opened this issue · 0 comments

Environment

  • Unimport: v3.7.1
  • Node: v18.16.1

Reproduction

https://github.com/aklinker1/unimport-tsx-bug

pnpm i
node index.mjs

Describe the bug

When components/index.ts exports a subdirectory with a index.tsx file in it, an error is throw (see logs below).

https://github.com/aklinker1/unimport-tsx-bug/blob/56985dab7724fae0c3e28f3801d6b3297bb2eed3/components/index.ts#L1

Same error is thrown if the file is components/Iframe/index.jsx.

There is a work-around, change the export in components/index.ts:

-export * from "./Iframe";
+export * from "./Iframe/index.tsx";

Additional context

This issue originates from: wxt-dev/wxt#440

I did some research into this and it appears we just need to add "tsx" and "jsx" to the file extensions array?

const FileExtensionLookup = [
'.mts',
'.cts',
'.ts',
'.mjs',
'.cjs',
'.js'
]

#229 fixed this for non-JSX files.

Logs

$ node index.mjs
node:internal/process/esm_loader:97
    internalBinding('errors').triggerUncaughtException(
                              ^

[Error: EISDIR: illegal operation on a directory, read] {
  errno: -21,
  code: 'EISDIR',
  syscall: 'read'
}

Node.js v18.16.1