FredKSchott / snowpack

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

🐛 BUG: when a file only has types,this file will cause 404 error #3585

Open ykan opened 3 years ago

ykan commented 3 years ago

Quick checklist

What package manager are you using?

yarn

What operating system are you using?

macOS

Describe the bug

I have a component , the file struct is like:

- src/components/Text
  - Text.tsx // component
  - types.ts // ts types
  - index.ts // export

Then I use like this:

<Text content="Hello, world." />

And I found this error:

[snowpack] [404] /dist/components/Text/types.js
  ✘ /sandbox/src/components/Text/types.ts

Steps to reproduce

  1. npx create-snowpack-app snowpack-dev --template @snowpack/app-template-react-typescript --use-yarn
  2. add a component like this : https://codesandbox.io/s/beautiful-hermann-44wde
  3. check the types.ts file,if you add export const a = 1 , it will turn right.
  4. Error! Describe what went wrong (and what was expected instead)...

Link to minimal reproducible example (optional)

https://codesandbox.io/s/beautiful-hermann-44wde

Olli-palkkaus commented 3 years ago

I am also facing this issue. Until there is a fix, I could modify the files that are causing the issue to get rid of these 404 errors, but could someone suggest potential options how to do it?

This discussion suggests a working hack: https://github.com/snowpackjs/snowpack/discussions/1589 Basically adding any code that emits as JavaScript to these interface files like types.ts in this case:

export interface TextProps {
  content?: string;
}

export const _SNOWPACK_HACK = true; // https://github.com/snowpackjs/snowpack/issues/3585

But is there anything more elegant? I could potentially restructure my project in a way that all my interfaces are in one folder / barrel (index.ts-file). Could I then get that whole barrel ignored in Snowpack some way? I need to export them for my rollup build, so removing the interface exports completely is not a solution. And also not having a barrel-file (referencing interfaces one-by-one) seems a bit clumsy.


EDIT: The above code has a problem when you apply it to multiple files. This works better (essentially, I just run a noop instead of exporting anything):

(()=>{ /* Snowpack Noop HACK for: https://github.com/snowpackjs/snowpack/issues/3585 */ })();
aardvarkk commented 2 years ago

I'm getting this too. I don't know how more people aren't running into this.

I just get a stream of 404s for most of the shared/helper files in my project that just expose types. At first I thought the entire build was broken, but then noticed that only some of them were giving 404s/missing in the output and theorized it might be because they only contained types. I tried to track down what was up with this earlier in the day, and I think the problem is around esbuild basically generating an empty-string output for the file, which then makes snowpack think it wasn't valid.