Basic react server side rendering does not work on Deno Deploy but does locally
The below application work correctly locally but fails on Deno Deploy. On Deno Deploy, all my responses have a status 500 and logs show an error
I am sure that I am doing something stupid but I cannot figure out what. Can you help me spot it. cheers, didier
ReferenceError: h is not defined at handler (file:///src/server.tsx:8:33)
.I am sure that I am doing something stupid but I cannot figure out what. Can you help me spot it. cheers, didier
5 Replies
Hello Didier,
The error message
ReferenceError: h is not defined
suggests that the JSX transformer is not able to find the function h
which is used to create elements in JSX. In React, this function is usually React.createElement
, but in Preact and some other libraries, it's often named h
.
In your code, you're using React, but you haven't specified a JSX transformer. This can be done using a special comment at the top of your file, like this:
This tells Deno to use the specified module (https://esm.sh/react
in this case) as the source for the JSX transformer.
However, Deno Deploy currently does not support this pragma. As a workaround, you can manually call React.createElement
for your components. Here's how you can modify your code:
This should resolve the ReferenceError: h is not defined
error.
Let me know if you have any other questions! 🦕Thanks alot @Deno AI Helper . It worked.
You're welcome, Didier! I'm glad to hear that it worked. If you have any more questions or run into any other issues, feel free to ask. Happy coding! 🦕
🦕💚 I'm glad I was able to help!