T
T
t800zippygod2020-08-02 22:24:21
React
t800zippygod, 2020-08-02 22:24:21

Error when SSR React app?

Good day) such an interesting problem arose. I'm rewriting a React app with SSR rendering, and on page load it throws an error: "Uncaught SyntaxError: Unexpected token '<'" . At the same time, it renders the text of the Header component, but without styles. Without SSR everything works ok.
Connected Babel on the server: at the entry point, I first call @babel/polyfill and @babel/register with @babel/preset-env and @babel/preset-react plugins. Then I call the file in which the server logic is written.
In the server file, I simply replace the contents of div#root with the string received via ReactDOMServer.renderToString.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tikhon Ermakov, 2020-08-03
@the_goldmayer

Type error. You need to look at the code. Somewhere something like this happened:

function func(string) { return string }

func( {title: 'Hello' } );

Most likely, you are passing jason data to some function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question