createWriteStream: Ignore error in fs.unlinkSync
Looks like Node's fs.createWriteStream sometimes fails to create a file at all, which would mean that unlinkSync() tries to delete a file that doesn't exist resulting in the error. (Or maybe there's a writestream error after the file was renamed?)
I don't know though why it happens only rarely on Windows and apparently nowhere else.
Closes https://github.com/parcel-bundler/parcel/issues/8571 Closes https://github.com/parcel-bundler/parcel/issues/8615
Benchmark Results
Kitchen Sink ✅
Timings
| Description | Time | Difference |
|---|---|---|
| Cold | 1.83s | +19.00ms |
| Cached | 411.00ms | -9.00ms |
Cold Bundles
No bundle changes detected.
Cached Bundles
| Bundle | Size | Difference | Time | Difference |
|---|---|---|---|---|
| dist/legacy/parcel.7cdb0fad.webp | 102.94kb | +0.00b | 308.00ms | +200.00ms ⚠️ |
| dist/legacy/parcel.7cdb0fad.webp | 102.94kb | +0.00b | 307.00ms | +198.00ms ⚠️ |
| dist/modern/parcel.7cdb0fad.webp | 102.94kb | +0.00b | 307.00ms | +199.00ms ⚠️ |
React HackerNews ✅
Timings
| Description | Time | Difference |
|---|---|---|
| Cold | 11.65s | +114.00ms |
| Cached | 508.00ms | -16.00ms |
Cold Bundles
No bundle changes detected.
Cached Bundles
No bundle changes detected.
AtlasKit Editor ✅
Timings
| Description | Time | Difference |
|---|---|---|
| Cold | 2.10m | +841.00ms |
| Cached | 2.62s | +102.00ms |
Cold Bundles
No bundle changes detected.
Cached Bundles
No bundle changes detected.
Three.js ✅
Timings
| Description | Time | Difference |
|---|---|---|
| Cold | 8.23s | +6.00ms |
| Cached | 336.00ms | -33.00ms 🚀 |
Cold Bundles
No bundle changes detected.
Cached Bundles
No bundle changes detected.
@mischnic I was having similar issues, and after applying your fix as a yarn patch it got better but still got this error:
× Build failed.
@parcel/compressor-raw: EPERM: operation not permitted, rename D:\test\dist\index.html.12768.5c' -> 'D:\test\dist\index.html'
Error: EPERM: operation not permitted, rename 'D:\test\dist\index.html.12768.5c' -> 'D:\test\dist\index.html'
Does this solution work perfectly or still has some issues?
No, that should not be happening.
Previously, it would have tried to delete D:\test\dist\index.html.12768.5c but after my change, that error was silence. And now it tries to use that file somewhere else. So the question is why that file wasn't created in the first place
@mischnic I havent checked Parcel source that much, but perhaps there are multiple threads running (idk if Parcel is multi-threaded), and something deleted that file already previously? Seems like some kind of race condition.
Now after your intial fix it was way harder for me to get any errors, but still managed to get this one 😅
multiple threads
That is exactly the reason why we added this atomic write stream in the past. For the distdir, multiple threads writing the same file is probably unwanted. But there are other places (writing to cache) where it can still happen
For what it's worth,I have the same problem as @partyvaper above, adding try/catch over unlink fixes this exact issue (I'm on Windows), but then I see another frequently (not always):
🚨 Build failed.
@parcel/compressor-raw: EPERM: operation not permitted, rename 'D:\My\dist\index.6b815632.js.map.10664.a' -> 'D:\My\dist\index.6b815632.js.map'
Error: EPERM: operation not permitted, rename 'D:\My\dist\index.6b815632.js.map.10664.a' -> 'D:\My\dist\index.6b815632.js.map'
The good news is this new error (that I didn't have before the try/catch) doesn't break the whole parcel process so I can trigger any change (save a file for example, I use the watch command) and it works again. Not super, but better.
Hello guys, I am experiencing the same issue, posted the error here: https://github.com/parcel-bundler/parcel/issues/8571