vite-plugin-dts icon indicating copy to clipboard operation
vite-plugin-dts copied to clipboard

Error: ENOTEMPTY: directory not empty, rmdir during rollup

Open MrMaxie opened this issue 11 months ago • 2 comments

Describe the bug

I'm just setting rollupTypes value to true, like:

dtsPlugin({
    rollupTypes: true,
}),

But it's enough to have issues in case of my code.

vite v5.0.10 building for production...
✓ 175 modules transformed.

[vite:dts] Start generate declaration files...
dist/style.css                 86.12 kB │ gzip: 11.54 kB
dist/App.js                     0.49 kB │ gzip:  0.23 kB
dist/[...].js                   1.68 kB │ gzip:  0.67 kB
dist/[...].js                   2.43 kB │ gzip:  0.81 kB
dist/[...].js                 108.06 kB │ gzip: 18.00 kB
[vite:dts] Start rollup declaration files...
Analysis will use the bundled TypeScript version 5.3.3
[vite:dts] ENOTEMPTY: directory not empty, rmdir 'E:/[...]/app/dist/[component-path]'
✓ built in 18.17s
error during build:
Error: ENOTEMPTY: directory not empty, rmdir 'E:/[...]/app/dist/[component-path]'
    at rmdirSync (node:fs:1219:10)
    at removeDirIfEmpty (file:///E:/[...]/app/node_modules/vite-plugin-dts/dist/index.mjs:126:5)
    at removeDirIfEmpty (file:///E:/[...]/app/node_modules/vite-plugin-dts/dist/index.mjs:111:14)
    at removeDirIfEmpty (file:///E:/[...]/app/node_modules/vite-plugin-dts/dist/index.mjs:111:14)
    at Object.writeBundle (file:///E:/[...]/app/node_modules/vite-plugin-dts/dist/index.mjs:1004:11)
    at async Promise.all (index 0)
    at async PluginDriver.hookParallel (file:///E:/[...]/app/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:18570:9)
    at async file:///E:/[...]/app/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:19562:13
    at async catchUnfinishedHookActions (file:///E:/[...]/app/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:18986:16)
    at async build (file:///E:/[...]/app/node_modules/vite/dist/node/chunks/dep-R0I0XnyH.js:66815:22)

I am close to certain that this is due to how the built-in FS library works on Windows. It is also significant that the folder is indeed non-empty. So it's probably a matter of a race of conditions.

What do I suggest? I suggest using libraries that already assume such scenarios and allow recursive folder deletion regardless of the operating system (fs-extra?)

Reproduction

Non-applicable

Steps to reproduce

  1. Create scaffolded project npm create vite@latest
  2. Create multilevel nested directories with multiple files, e.g components
  3. Install vite-plugin-dts
  4. Set-up plugin like instructions say, with rollupTypes equal to true
  5. Run vite build or npm run build

Note: I do not have 100% reproductive scenario. In some projects there are this issue, in others works fine.

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 1.31 GB / 15.88 GB
Binaries:
    Node: 20.10.0 - ~\scoop\apps\nvm\current\nodejs\nodejs\node.EXE
    npm: 10.2.5 - ~\scoop\apps\nvm\current\nodejs\nodejs\npm.CMD

Validations

MrMaxie avatar Mar 07 '24 17:03 MrMaxie

Is it reproduced absolutly when building?

qmhc avatar Mar 08 '24 01:03 qmhc

I cannot reproduce this via the steps you provided. Please provide a reprodution.

qmhc avatar Mar 19 '24 13:03 qmhc