unjs / c12

āš™ļø Smart Configuration Loader
MIT License
538 stars 19 forks source link

EISDIR: illegal operation on a directory, read #147

Closed sadeghbarati closed 1 month ago

sadeghbarati commented 8 months ago

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

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 components 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\jiti@1.21.0\node_modules\jiti\dist\jiti.js:1:254411)
    at resolveConfig (file:///***/Projects/Vue/c12-error/node_modules/.pnpm/c12@1.10.0/node_modules/c12/dist/index.mjs:330:26)
    at loadConfig (file:///***/Projects/Vue/c12-error/node_modules/.pnpm/c12@1.10.0/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'
}
pi0 commented 8 months ago

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)

dargmuesli commented 7 months ago

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?

pi0 commented 1 month ago

Confirmed on 1.11.2. https://github.com/unjs/c12/pull/188 fixed it.