cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.6k stars 674 forks source link

🐛 BUG: `pages dev` does not reload when empty import is not "empty" anymore #6182

Open CarmenPopoviciu opened 3 months ago

CarmenPopoviciu commented 3 months ago

Which Cloudflare product(s) does this pertain to?

Pages

What version(s) of the tool(s) are you using?

3.63

What version of Node are you using?

18.20.0

What operating system and version are you using?

MacOS Sonoma 14.4.1

Describe the Bug

Say we have the following:

When we run pages dev with this project setup, any changes made to the add.ts file will trigger Functions to rebuild. This works as expected.

Now imagine we delete the contents of add.ts (not the file itself!!) but leave everything else as it is. In the terminal, we'll get a compile warning saying Import "add" will always be undefined because the file "../math/add.ts" has no exports which is what is expected.

At this point, IMHO, add.ts is technically still a dependency of math-is-fun.ts (but happy to hear what others think), since it is still imported in the Functions code. My expectation in this case, would be that if we were to undo the changes we made in add.ts, that would trigger a Functions rebuild as well. This works as expected if esbuild was in watch mode, but it does not trigger anything in the current implementation.

The reason for that is that the metafile returned by esbuild does list add.ts as an input, but it does not list it as an input to the entrypoint, which means we won't return it as part of bundle.dependecies 😕. The returned metafile BTW, looks exactly the same in both esbuild/chokidar watch modes. So, it's either that esbuild watches more files than what it returns in the metafile, or we're making some wrong assumptions when we process that metafile to return bundle.dependencies, or there is a plugin somewhere that strips out empty imports? (meaning of 0kb in size).

Whatever it is, the finding is a tad worrying...cause it makes me wonder...what other corner cases I didn't think of yet, would result in a similar behaviour 🫠 ... and can we really rely on bundle.dependencies as a correct source of truth?

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response