unplugin / unplugin-auto-import

Auto import APIs on-demand for Vite, Webpack and Rollup
MIT License
3.29k stars 198 forks source link

Failed parsing of `.eslintrc-auto-import.json` #444

Open marlass opened 12 months ago

marlass commented 12 months ago

Describe the bug

webpack + unplugin-auto-import combination sometimes fail on parsing .eslintrc-auto-import.json.

image

From quick checks I've managed to find 2 conditions for this error to occur.

  1. Sometimes eslint file is read while it's being written to (case from the screenshot).
  2. Sometimes there are multiple concurrent writes to this file. Then .eslintrc-auto-import.json is corrupted.

    {
    "globals": {
      "IconPhLinkBreak": true,
      "IconPhLinkSimpleHorizontalBreak": true
    }
    }
    
      "IconHeroiconsShoppingCart20Solid": true,
      "IconPhLinkBreak": true,
      "IconPhLinkSimpleHorizontalBreak": true
    }
    }

Both of these cases fail on the parseESLint, as there isn't any try {} catch around parsing and fallback return. There was already one issue #143 about this, but it was closed due to lack of info. Hope these details will be enough.

Not sure how to fix the file locking which I guess would be the best fix, but even error handling in JSON parsing generally helps to recover from this problem.

Reproduction

It's hard to reproduce as typical race conditions problems. I can't reproduce it locally on my machine. It only happens on the basic GH Actions runner. Maybe that's because of the slower disk and bigger chance of double write or write with read occuring at the same time.

System Info

System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M1 Pro
    Memory: 239.06 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.4.0 - ~/code/proj-devbox/.devbox/nix/profile/default/bin/node
    Yarn: 1.18.0 - ~/code/proj-devbox/.devbox/nix/profile/default/bin/yarn
    npm: 9.7.2 - ~/code/proj-devbox/.devbox/nix/profile/default/bin/npm
  Browsers:
    Chrome: 119.0.6045.159
    Safari: 17.0

Used Package Manager

yarn

Validations

exherb commented 11 months ago

same here