FredKSchott / snowpack

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️
https://www.snowpack.dev
MIT License
19.48k stars 921 forks source link

Fix 404s in dev and "Module not found" in production for TS files containing only types #3822

Open aardvarkk opened 2 years ago

aardvarkk commented 2 years ago

When building a TS file with only types, esbuild strips out all of the type info and returns an empty string as the result of the compilation (''). loadUrl() just does a falsy check on the return value from fileBuilder.getResult, which can be any of string | Buffer | undefined. When the empty string is returned, the falsy check doesn't pass, so the load appears to be unsuccessful even though the empty string indicates successful output. Changing the falsy check to an explicit check for undefined allows the empty string to be treated as a successful response.

An alternative to this approach might be to just ignore the import entirely (somehow) if the response is empty. That would potentially save a bunch of useless requests from being sent. But this is at least a step in the right direction that helps code like this to be runnable at least.

Changes

Testing

Docs

changeset-bot[bot] commented 2 years ago

⚠️ No Changeset found

Latest commit: 16eb92c1b4847bd03855fb0e173ca65ce08d1b98

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

vercel[bot] commented 2 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/3PA4cScJCtGDFXh9ZZfYQVz97zJv
✅ Preview: https://snowpack-git-fork-aardvarkk-main-pikapkg.vercel.app