parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.53k stars 2.27k forks source link

Renaming/deleting a file matched by the glob resolver causes `Failed to resolve './x2.js' from './x*.js'` #6875

Open mischnic opened 3 years ago

mischnic commented 3 years ago

🐛 bug report

When removing a file matched by @parcel/resolver-glob, an error occurs:

*After applying the workaround in https://github.com/parcel-bundler/parcel/issues/6874, otherwise you get `ENOENT: no such file or directory, open '/Users/niklas/Desktop/x/x.js'`**

🚨 Build failed.

@parcel/core: Failed to resolve './x2.js' from './x*.js'

  /Users/niklas/Desktop/x/x*.js:2:24

@parcel/resolver-default: Cannot load file './x2.js' in './'.
💡 Did you mean './x1.js'?
💡 Did you mean './y2.js'?

🎛 Configuration (.babelrc, package.json, cli command)

{
  "extends": "@parcel/config-default",
  "resolvers": ["@parcel/resolver-glob", "..."]
}

🤔 Expected Behavior

No error, rebuild without that file.

😯 Current Behavior

See error above.

💁 Possible Solution

I think this happens because the request to rerun the transformer is invalidated before the resolver is rerun.

💻 Code Sample

import * as foo from "./x*.js";

console.log(foo["1"].x);
console.log(foo["2"].x);

x1.js:

export const x = 1;

x2.js:

export const x = 2;
  1. Setup project, run yarn parcel build index.js. Builds as expected (with two files matched by the glob)
  2. Delete x2.js
  3. Rerun yarn parcel build index.js, the error occurs.

🔦 Context

This happened for me when writing a custom resolver, so this needs to be fixed in core.

🌍 Your Environment

{
  "dependencies": {
    "@parcel/config-default": "2.0.0-nightly.826",
    "@parcel/resolver-glob": "2.0.0-nightly.2448",
    "parcel": "2.0.0-nightly.824"
  }
}
windware-ono commented 2 years ago

I have the same problem.

The bad part is that this will stop the bundling process until I remove .parcel-cache and restart the parcel process and until then, it will keep failing saying that it can't find some non existent file. (In my case, it complains it can't find *.js when I'm only specifying *.styl in the glob resolver.)

It works fine when adding a new file, but deleting the file needs manual intervention to fix the parcel process.

LeoDog896 commented 1 year ago

This is most likely due to an incorrect cache validation in part of parcel's glob. I'm not sure if it's a limitation of parcel's invalidation, but in order for it to work, it needs to watch every possible globbed file by listening to the parent directory.

wiebekaai commented 1 year ago

Same issue when removing a file: Error: ENOENT: no such file or directory, open '.../src/*.js'.

sealedsins commented 1 year ago

I use it to watch and automatically reload assets in my visual novel engine, and this issue really annoys me. Any workarounds so far?..