Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

astro build does not produce any static routes when using import.meta.glob on Svelte <script module="context"> #7096

Closed
1 task
iivvaannxx opened this issue May 15, 2023 · 2 comments

Comments

@iivvaannxx
Copy link

iivvaannxx commented May 15, 2023

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 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

const importResult = await module() as any

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

  • I am willing to submit a pull request for this issue.
@iivvaannxx 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 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
@iivvaannxx
Copy link
Author

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.

@bluwy
Copy link
Member

bluwy commented Jun 13, 2023

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.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants