-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Middleware imports are not being resolved properly in a TS project #7017
Comments
Even better than
|
Hmmm... I see. Then, what's the workaround? Set ourselves the resolution? Or should Astro provide types in a different strategy, such as having a central |
Updating our astro/packages/astro/package.json Lines 16 to 25 in 50bf66e
|
Thanks for the tip @bluwy . I opened a PR to apply this change and it fixed the problem indeed. |
What version of
astro
are you using?2.4.1
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
pnpm
What operating system are you using?
Mac
What browser are you using?
not relevante
Describe the Bug
Hey peps. 👋
First, thanks for finally adding
middleware
to Astro. This was a feature I had been waiting for so long, mainly because Vercel's middleware is very restrictive in what we can import and do.Problem
Anyhow, I have an Astro project in TS, and while trying to follow the documentation example (the sequence one, for example), I noted one thing: the types are not being resolved:
That's a bit odd. I went down to Astro's module to see if the exports are declared in the package.json, and actually they are:
If it's declared... I wasn't sure why the heck it wasn't working.
Then, I remembered I did some investigation a while ago about how the conditional types export (
exports[number].types
) are not always resolved in the IDE, kind of forcing us to rely on a single.d.ts
export.But visiting this, I found a possible solution based on this issue (microsoft/TypeScript#50794) opened on the TypeScript repository.
In summary,
"moduleResolution": "node"
can't handle these conditional exports and that's the option we have set in Astro'sbase.json
:@andrewbranch states:
Then, I have overridden the
moduleResolution
tonode16
to see if that would fix the problem, and it did:Solution
If it's said that Astro's project has to use Node 14+, does it make sense to change the
base.json
tomoduleResolution: node16
?Steps to reproduce
astro/middleware
import isn't working (for TS only);tsconfig.json
and uncomment thecompilerOptions
that setsmoduleResolution
tonode16
and save the file;src/middleware.ts
);Link to Minimal Reproducible Example
https://stackblitz.com/github/devraul/astro-middleware-types?file=src/middleware.ts
Participation
The text was updated successfully, but these errors were encountered: