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

Error fn is not a function when Astro.glob in a TS file #5552

Closed
1 task done
goulvenclech opened this issue Dec 7, 2022 · 3 comments · Fixed by #7204
Closed
1 task done

Error fn is not a function when Astro.glob in a TS file #5552

goulvenclech opened this issue Dec 7, 2022 · 3 comments · Fixed by #7204
Labels
- P2: has workaround Bug, but has workaround (priority) feat: errors Related to error handling / messages (scope)

Comments

@goulvenclech
Copy link
Contributor

goulvenclech commented Dec 7, 2022

What version of astro are you using?

1.6.13

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

NPM

What operating system are you using?

Tested on Linux, Mac & Windows

Describe the Bug

Hi guys !

I tried to use await Astro.glob inside a TS file by passing Astro as an argument. Throw the error "FN is not a function", looks like a Vite-related problem.

The same function works like a charm when in an Astro file.

Error log

fn is not a function

/home/projects/github-xlqiz4/globHandler/<@file:/file:/home/projects/github-xlqiz4/node_modules/astro/dist/runtime/server/astro-global.js:28:47

globHandler/<@file://file:///home/projects/github-xlqiz4/node_modules/astro/dist/runtime/server/astro-global.js:28:47
globHandler@file://file:///home/projects/github-xlqiz4/node_modules/astro/dist/runtime/server/astro-global.js:28:35
getStaticPathFromContentType@/src/utils.ts:4:32
getStaticPaths@/home/projects/github-xlqiz4/src/pages/blog/[article].astro:10:32
callGetStaticPaths@file://file:///home/projects/github-xlqiz4/node_modules/astro/dist/core/render/route-cache.js:38:27
getParamsAndProps@file://file:///home/projects/github-xlqiz4/node_modules/astro/dist/core/render/core.js:41:47
matchRoute@file://file:///home/projects/github-xlqiz4/node_modules/astro/dist/vite-plugin-astro-server/route.js:43:59

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-xlqiz4?file=src/utils.ts

Participation

  • I am willing to submit a pull request for this issue.
@Princesseuh Princesseuh added the - P2: has workaround Bug, but has workaround (priority) label Dec 7, 2022
@Princesseuh
Copy link
Member

Princesseuh commented Dec 7, 2022

Tried to quickly debug this on my end and it seems like importMetaGlobResult here is somehow an array of strings instead of being an array of imports. I'm guessing this happens because in a .ts files Astro.glob doesn't get processed correctly or something like that (or processed at all, now that I think about it. Our Vite plugin only works inside Astro files)

If we can't fix the underlying problem, we should at least provide a better error message pointing towards using import.meta.glob

goulvenclech added a commit to gamedevalliance/fairedesjeux.fr that referenced this issue Dec 7, 2022
getStaticPathFromContentType add a standardized way to get static path.
But the function throw an obscure error when used in TS files,
See this issue -> withastro/astro#5552
goulvenclech added a commit to gamedevalliance/fairedesjeux.fr that referenced this issue Dec 7, 2022
getStaticPathFromContentType add a standardized way to get static path.
But the function throw an obscure error when used in TS files,
See this issue -> withastro/astro#5552
@Princesseuh Princesseuh changed the title Error fn is not a function when passing Astro to a TS file Error fn is not a function when Astro.glob in a TS file Jan 13, 2023
@bluwy
Copy link
Member

bluwy commented May 25, 2023

I think this is expected as documented at https://docs.astro.build/en/reference/api-reference/#astroglob. Closing this for now.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 2023
@bluwy
Copy link
Member

bluwy commented May 25, 2023

Actually we could have better error messages when detecting the value that's passed in to Astro.glob, so re-opening 😅

@bluwy bluwy reopened this May 25, 2023
@Princesseuh Princesseuh added the feat: errors Related to error handling / messages (scope) label May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) feat: errors Related to error handling / messages (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants