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

Layout groups causing import.meta.glob to fail to find files #6239

Closed
hyyyper opened this issue Aug 24, 2022 · 4 comments · Fixed by #6398
Closed

Layout groups causing import.meta.glob to fail to find files #6239

hyyyper opened this issue Aug 24, 2022 · 4 comments · Fixed by #6398
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. vite
Milestone

Comments

@hyyyper
Copy link

hyyyper commented Aug 24, 2022

Describe the bug

This code does not returning anything when inside a layout group:

export async function GET() {
    const glob = import.meta.glob("../**/*.md")
    console.log("(web) glob...")
    console.log(glob)

    return new Response(JSON.stringify({ glob: Object.keys(glob) }))
}

In the repro, I made two routes that do the exact same thing...
(web)/blog/posts.json/+server.js
/it-works/blog/posts.json/+server.js

But it only works outside of the (web) layout group. 🤔

Reproduction

https://github.com/hyyyper/sveltekit-glob-repro

Logs

(web) glob...
{}

/it-works glob...
{ '../sample-post/+page.md': [Function: ../sample-post/+page.md] }

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (16) x64 AMD EPYC 7B13
    Memory: 42.47 GB / 62.80 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.17.0/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.0/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.66 
    @sveltejs/kit: next => 1.0.0-next.435 
    svelte: ^3.44.0 => 3.49.0 
    vite: ^3.0.4 => 3.0.9

Severity

blocking an upgrade

Additional Information

No response

@amr3k
Copy link
Contributor

amr3k commented Aug 24, 2022

I can confirm this bug.

@amr3k
Copy link
Contributor

amr3k commented Aug 25, 2022

Just a quick update, I tried ../../**/+page.svx instead of ./**/+page.svx and it works!

Not sure why the path changed, but I'll take that for now.

@dummdidumm
Copy link
Member

dummdidumm commented Aug 25, 2022

First investigations suggest it's a bug in fast-glob, since that one doesn't return any results for the glob. My guess is that at some point a regex is used and it doesn't escape the ( and ) characters. If I escape them myself it works as expected. Edit: This seems like a bug in Vite after all (thanks @dominikg!) since fast-glob treats some characters as special (like ( or )) and Vite needs to escape them before passing it on. Edit 2: Got the culprit in the vite codebase, it's the toAbsoluteGlob method not escaping things in the path leading up to the glob. Upstream issue created: vitejs/vite#9833

@dummdidumm dummdidumm added bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. labels Aug 25, 2022
@dummdidumm dummdidumm added this to the 1.0 milestone Aug 25, 2022
@dominikg
Copy link
Member

workaround: use a / at the start so vite only prepends the root directory, then you can add the needed escapes yourself

import.meta.glob('/src/routes/\\(name\\)/**/*.md')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc. vite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants