tRPC Client webpack error
As soon as I add the client part to my legacy app i get an error and Can't figure out what is wrong.
33 Replies
As soon as I add the wrapper it crashes
hmmmmmmmmm it might be that the compiled output is too "modern"?
it looks like it's complaining about that optional chaining line
interesting
looking at the compiled output it seems like we're not transpiling optional chaining but we are transpiling i.e. async/await (which I think is an older feature in browsers?)
@julius this feels like your territory. we used to use babel for this stuff - do you think we need to do anything here?
it seems like all environments are extending this tsconfig (https://github.com/trpc/trpc/blob/main/tsconfig.build.json) but i think we might need some lower compile target for browser-facing stuff?
if this is a monorepo with nextjs you should use next-transpile-packages or the experimental option in next13
https://github.com/t3-oss/create-t3-turbo/blob/20a00f1e2146a24ca3f47f7a9b2509356655abd7/apps/nextjs/next.config.mjs#L14
you get that loader error if you dont do that
not sure if this is the same scenario though
oh wait it complains about some file within trpc 🤔
is it the optional chaining then which doesn't work for legacy stuff?
do we care about that? like isn't that pretty old stuff?
i think we should, one of the superpowers of trpc is that you can add it to legacy project and incrementally migrate
https://caniuse.com/?search=Proxy
https://caniuse.com/?search=nullish%20coalescing
Proxy is a must for trpc to work but we should probably do something that does the nullish coalescing etc
i'm perplexed that it rewrites async/await (https://caniuse.com/async-functions) but not nullish coal
we could rewrite this row to be 😉
https://github.com/trpc/trpc/blob/87024b2012a5cbcf593850d0323fb273a408ac46/packages/client/src/internals/TRPCClient.ts#L120
if thats the only place
nullish seems to have come a tad bit later than async
is it just a target in the tsconfig or do we need babel stuff?
i'm having a play with it now...
cool, im still fighting with my bloody matrix.........
seems like i can't do it easily
@Mugetsu can you have a look at https://stackoverflow.com/questions/58813176/webpack-cant-compile-ts-3-7-optional-chaining-nullish-coalescing?
what version of webpack/babel are you using?
Stack Overflow
Webpack cant compile ts 3.7 (Optional Chaining, Nullish Coalescing)
I try to use typescript 3.7 features like Optional Chaining, Nullish Coalescing. But webpack gives me an error while transpaling.
app: Module parse failed: Unexpected token (50:40)
app: File was
GitHub
feat: add
@babel/runtime
for client packages · Issue #3393 · trpc...Describe the feature you'd like to request Currently, we don't do any transpilation outside of what's in tsconfig, which leads to limited browser support, even in compiled o...
@alex / KATT
Solution from the stackoverflow you linked didn't help.
I do have already
In my babelrc
But thanks to this link I was able to track this a bit and found this
https://github.com/webpack/webpack/issues/10227
Which worked.
I've added this to package.json and webpack compiled successfully.
Now I have a different problem as when I want to use the query it complains
>QueryClientProvider.js:58 Uncaught Error: No QueryClient set, use QueryClientProvider to set one
Dunno why is this happening. I've wrapped my whole app within the TrpcWrapper from above
https://discord.com/channels/867764511159091230/1052253855884263484/1052254812185563166
and it still complain.
if it's a monorepo, this might come that you have multiple versions of tanstack query installed
I had tanstack query installed prior trpc. But I dont see why it would happen? I installed fresh newest version of tanstack. I expect that this would run two separate instances of ReactQuery and work? My raw reactquery works but trpc complains.
I've tried clean setup with trpc with commits before I introduced raw tanstack query and its the same behaviour.
No QueryClient set, use QueryClientProvider to set one
@alex / KATT is there anything more you could recommend I could check what could be the issue here?I think it is that you need to have the QueryClientProvider further up the tree than the trpc initialization
hmm
nooo, that can't be it
well in the code above you have two query client providers, it might be that?
I've checked that and It doesn't seem this is the issue
Dunno what I miss here... QueryClientProvider is there why it complains for god sake 😭
does it complain when you add a query or mutation?
query havent checked mutation
we purposefully transpile to whatever node 14 supports (I think es2020)
@alex / KATT This solved the problem. But why I would need to do this ??
https://github.com/TanStack/query/discussions/4619
we can lower that target if you want @alex / KATT
if tsconfig is enough, that's great, i played around briefly yday and couldn't get tsconfig to transpile optional chains
are you sure you don't have several react-query in node_modules?
I think there's a way to set it so it uses the tsconfig target
Im pretty sure. How I verify that?
I guess this should be okay? Having two react-query. One from tanstack and second from trpc ??
@Mugetsuis it a must for you to be on webpack 4 (i.e. it's too hard to move off of it)?
That looks fine
@sachin I tried but the dependency chain in this legacy app (more than 3 yrs oldd) is a nightmare and overwhelm me with upgrade try. I might try again. But Anyway i was able to successfuly run trpc with the found workarounds
great!!
Hey, can you say me more about this.
I am running into this problem , I'm using turborepo with next13
Advanced Features: Next.js Compiler | Next.js
Learn about the Next.js Compiler, written in Rust, which transforms and minifies your Next.js application.
got it thanks.