You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was developing a component for a website I am currently making which acts as a Facade Svelte component. It works by using import.meta.glob to load all the *.svelte components in the same folder and then conditionally rendering them depending on a name prop which is given to that same Facade.
At first, I didn't run into any problems, I coded it, and it was working without any problems (in dev mode), until I tried a build. When I went to check my build output (static) I was surprised that I didn't have any static .html file in the folder. I just didn't know what could be causing the issue, and I started commenting parts of my source code and rebuilding until I managed to isolate the issue into what I explained just above. I am not sure if this is some edge case or it's actually expected behavior (somehow) because of my use case of import.meta.glob but I didn't find anything on the documentation so I ended up creating this issue.
I created a minimal reproducible example which is linked below. It just has a simple implementation of the Facade component and two dummy components Foo and Bar which can be rendered through that facade. There's also a HelloWorld component which I simply made to render something into the page and test if Svelte was working correctly.
The Facade component is commented out, if you try to build it, it should generate the index.html page, but as soon as you uncomment it the build will not produce the expected result. As I said, if you try to run npm run dev the component does actuallty work.
Also, I think it's not that it's not producing the build at all, instead, I think it's actually creating a "dynamic"? build which could work using SSR, because it's generating a .mjs file with some 'recognizable' HTML source code inside. I don't have much idea, because I still never tried SSR, so don't mind me if I'm wrong.
EDIT: I forgot to mention that the line which causes the issue is this one:
File: facade.svelte Line: 11
constimportResult=awaitmodule()asany
If you comment or remove this line the build works as it should.
I am willing to submit a pull request for this issue.
The text was updated successfully, but these errors were encountered:
iivvaannxx
changed the title
astro build does not produce any static routes when using import.meta.glob on Svelte module <script>astro build does not produce any static routes when using import.meta.glob on Svelte context module <script>May 15, 2023
iivvaannxx
changed the title
astro build does not produce any static routes when using import.meta.glob on Svelte context module <script>astro build does not produce any static routes when using import.meta.glob on Svelte <script module="context">May 15, 2023
I solved this by adding { eager: true } as the options for the import.meta.glob function (see this) but still I find this a little weird so I am leaving the issue open in case needs revision. I don't know if it was me doing it in the wrong way, but still, I think that at the very least some error should be thrown. The build wasn't failing and producing no routes, I don't think that should be expected behaviour.
Unfortunately this is a Rollup bug (rollup/rollup#4708) due to the top-level await. Using { eager: true } would be the way around for now, since you're also directly importing the components afterwards. Otherwise the other workaround is to await import in a non top-level context, e.g. inside the Svelte component instance <script>.
Closing this for now as there's not much we can do to fix this.
What version of
astro
are you using?^2.4.5
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
pnpm
What operating system are you using?
Linux
What browser are you using?
Brave
Describe the Bug
I was developing a component for a website I am currently making which acts as a
Facade
Svelte component. It works by usingimport.meta.glob
to load all the*.svelte
components in the same folder and then conditionally rendering them depending on aname
prop which is given to that sameFacade
.At first, I didn't run into any problems, I coded it, and it was working without any problems (in dev mode), until I tried a build. When I went to check my build output (static) I was surprised that I didn't have any static
.html
file in the folder. I just didn't know what could be causing the issue, and I started commenting parts of my source code and rebuilding until I managed to isolate the issue into what I explained just above. I am not sure if this is some edge case or it's actually expected behavior (somehow) because of my use case ofimport.meta.glob
but I didn't find anything on the documentation so I ended up creating this issue.I created a minimal reproducible example which is linked below. It just has a simple implementation of the
Facade
component and two dummy componentsFoo
andBar
which can be rendered through that facade. There's also aHelloWorld
component which I simply made to render something into the page and test if Svelte was working correctly.The
Facade
component is commented out, if you try to build it, it should generate theindex.html
page, but as soon as you uncomment it the build will not produce the expected result. As I said, if you try to runnpm run dev
the component does actuallty work.Also, I think it's not that it's not producing the build at all, instead, I think it's actually creating a "dynamic"? build which could work using SSR, because it's generating a
.mjs
file with some 'recognizable' HTML source code inside. I don't have much idea, because I still never tried SSR, so don't mind me if I'm wrong.EDIT: I forgot to mention that the line which causes the issue is this one:
File:
facade.svelte
Line:11
If you comment or remove this line the build works as it should.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-4i4cer?file=src/pages/index.astro
Participation
The text was updated successfully, but these errors were encountered: