#Major bug: unused components are being imported on all pages

2 messages · Page 1 of 1 (latest)

magic badge
#

As raised over two years ago in this Github issue, unused components are brought into pages even when not imported. Here's a minimal reproducible example (linked from that issue): notice how the console log message from the Test.astro component runs on the index page even though it's not imported or used. Also, the Card component is commented out but it's still working (but shouldn't!). I'm creating a project with Astro and am facing major headaches with this seeming to be the root cause. This is inefficient, confusing, and unusable on many projects.

I love Astro and want it to succeed, but this is really a breaking bug that needs to be fixed. Am I missing something? I haven't found much discussion beyond that issue, so I would love to know if I'm doing something wrong and to see if others have noticed this.

shrewd wedge
# magic badge As raised **over two years ago** in this [Github issue](https://github.com/witha...

see this comment from the same thread. This is not something that is considered an issue, as it is doing exactly what it should be doing

However, this doesn't work if you decide to build dynamically the argument that you pass to import. This isn't Astro, it's how bundlers work nowadays (webpack, rollup, parcel, etc.):

const DynamicComponent = () => import("./components/"+ someVariableComingFromCms +".astro")

The bundler doesn't know what someVariableComingFromCms is, and it's not able to resolve it. I want you all to understand that a bundler is just an analyzer with steroids, but it's not a runtime, and even though it is, you end up shipping that code to production, and if that variable comes from a CMS... well, it's absolutely impossible to know which components need to be pulled.