TypeError: Failed to resolve module specifier "h3" after successful build for node-server preset
My app is able to build with
npm run build
, but my app is mostly not working once I run it. I see the following error in my console:
Since h3
is a dependency of Tanstack Start, I wanted to check here first to see if there is a potential issue with my build setup. Below is my app config:
11 Replies
foreign-sapphireā¢6mo ago
why configure those aliases and polyfills?
like-goldOPā¢6mo ago
With the given app.config:
I get this error:
foreign-sapphireā¢6mo ago
looks like you are calling some sever only functionality from the client
e.g. in a loader or a beforeLoad
like-goldOPā¢6mo ago
Oh OK, I am calling parseCookies in a try/catch that is executing on the frontend. I will try isolating that logic and see if my build works after that, will let you know
Can I use
getCookie
in a loader, or will it cause the same issue?foreign-sapphireā¢6mo ago
same issue
beforeLoad and loader are isomorphic, that means they run on both the server and the client
if you want something to always run on the server, you need to wrap it into a server function
there is also the option to have functions that behave differently on client and server. if you need that, then use
createIsormorphicFn
like-goldOPā¢6mo ago
I think that is what I need.
Here is the use case:
- On the server, I want to use a cookie which contains my Authorization header
- On the client, I want to call a method which will give me my Authorization header
Where are the docs for this?
foreign-sapphireā¢6mo ago
no docs yet š
its easy though
like-goldOPā¢6mo ago
This worked for me BTW, thank you!
fascinating-indigoā¢5mo ago
I wondering how did you access the headers or the cookies on the client?
foreign-sapphireā¢5mo ago
you dont access them on the client, you need a server function for that
like-goldOPā¢5mo ago
yeah i access cookies on the server and i have a function to access local storage for my header on the client