c12
c12 copied to clipboard
EISDIR: illegal operation on a directory, read
Environment
Tested with node v18.8.2 on Windows
and node 20.11.1 in macOS
and node v18.8.0 in StackBlitz
@pi0 sorry for the tag, but we very much need this fix in shadcn-vue 🙏
related issue in shadcn-vue https://github.com/radix-vue/shadcn-vue/issues/387
Reproduction
- https://stackblitz.com/github/sadeghbarati/c12-repro
- https://github.com/sadeghbarati/c12-repro
Describe the bug
Tested in
Windows 11 ❌ macOS ❌ StackBlitz ✅
Looks like c12 cannot resolve config when the name and config file are the same name as another directory like
components.json in the root
empty component directory (folder) in the root
Additional context
I think it's related to Jiti
Logs
Error: EISDIR: illegal operation on a directory, read
at Object.readSync (node:fs:751:3)
at tryReadSync (node:fs:451:20)
at readFileSync (node:fs:497:19)
at Object.jiti (***\Projects\Vue\c12-error\node_modules\.pnpm\[email protected]\node_modules\jiti\dist\jiti.js:1:254411)
at resolveConfig (file:///***/Projects/Vue/c12-error/node_modules/.pnpm/[email protected]/node_modules/c12/dist/index.mjs:330:26)
at loadConfig (file:///***/Projects/Vue/c12-error/node_modules/.pnpm/[email protected]/node_modules/c12/dist/index.mjs:140:40)
at getRawConfig (file:///***/Projects/Vue/c12-error/c12.js:27:34)
at main (file:///***/Projects/Vue/c12-error/c12.js:43:24)
at file:///***/Projects/Vue/c12-error/c12.js:48:1
at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {
errno: -4068,
syscall: 'read',
code: 'EISDIR'
}
Thanks for detailed reproduction it helps a LOT. I will be back to it but probably not this week, if you had time to investigate down to jiti (hint: I guess it is esm resolve and mlly) that would accelerate fixing this issue.
BTW: As best practice, please consider explicitly naming your config after your tool (not generic names like components or app)
It looks like at
https://github.com/unjs/c12/blob/77a58bed371b96cc4940bc05ed46fdef77292fe0/src/loader.ts#L316
jiti needs to be told to only try to resolve files, not directories, right?
Confirmed on 1.11.2. https://github.com/unjs/c12/pull/188 fixed it.