-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
withPlausibleProxy()
causes Union type that is too complex
for next.js Route
#112
Comments
hi! can you maybe share a small reproduction repo? |
I have tried reproducing it in a blank project, and I cannot. |
Even if I comment out the function which causes the error, type compilation increases from ~3 to ~30 seconds. Since this prohibits me from using the If I set <PlausibleProvider
domain='bar.com'
selfHosted
customDomain='https://foo.bar.com'
/> it will try to load the script from I want to be able to set an absolute path, for example: <PlausibleProvider
domain='bar.com'
selfHosted
customDomain='https://bar.com/friendly-script'
/> And then manually proxy How would I do that if I cannot use |
As a workaround until I find a better way, I recommend you disable statically typed links. |
Now I know why I couldn't reproduce it yesterday! I forgot to set Would there be another way to serve the script from a custom path without using |
Not for now, at least with You can overwrite the EDIT: you can skip |
The reason why it takes so long to process the types is because Click to see the whole union type
The reason why The easiest way to fix this would be to use a clever regex as rewrite instead of so many individual ones. However nextjs regex support for rewrites is limited and does not cover this use case. The next best option I see is to move away completely from import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import {isNextPlausibleRequest, proxyNextPlausibleRequest} from 'next-plausible'
export function middleware(request: NextRequest) {
if (isNextPlausibleRequest(request) {
return proxyNextPlausibleRequest(request)
}
} Although I like the simplicity of |
Thank you, this works! Probably obvious for you, but I will write it for others: you also need to set |
I have attached a video to show the problem. Once I wrap my next.js config in
withPlausibleProxy
the union type withRoute
becomes too complex. Type checking also becomes extremely slow, hence you have to skip around 30 seconds in the video until the error shows up.Error:
Expression produces a union type that is too complex to represent.
Kapture.2023-11-28.at.22.01.33.mp4
The text was updated successfully, but these errors were encountered: