React component problem #152

Closed
opened 2025-08-09 17:15:12 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @NickMaev on 2/25/2018

Hi all.
I have React component:

`
export class MyComponent extends React.Component<{}, {}> {
...
componentDidMount(){
// Now I want to initialize it in client-side rendering.
if(typeof window !== undefined) {
// jQuery code here...
/* But node thrown errors:
An unhandled exception occurred while processing the request.
NodeInvocationException: Prerendering failed because of error: TypeError: Cannot set property 'serializeJSON' of undefined

After I updated page second time, I've got:
An unhandled exception occurred while processing the request.
NodeInvocationException: Prerendering failed because of error: TypeError: $.extend is not a function
*/
}

// Furthermore:
if(false){ // <--FALSE
// jQuery code here...
/* But node thrown errors AGAIN!
An unhandled exception occurred while processing the request.
NodeInvocationException: Prerendering failed because of error: TypeError: Cannot set property 'serializeJSON' of undefined

After I updated page second time, I've got:
An unhandled exception occurred while processing the request.
NodeInvocationException: Prerendering failed because of error: TypeError: $.extend is not a function */
}
}
...
}

`

What should I do to prevent initialize scripts in server rendering and run it on client side only?
I am using React + Redux starter kit.

*Originally created by @NickMaev on 2/25/2018* Hi all. I have React component: ` export class MyComponent extends React.Component<{}, {}> { ... componentDidMount(){ // Now I want to initialize it in client-side rendering. if(typeof window !== undefined) { // jQuery code here... /* But node thrown errors: An unhandled exception occurred while processing the request. NodeInvocationException: Prerendering failed because of error: TypeError: Cannot set property 'serializeJSON' of undefined After I updated page second time, I've got: An unhandled exception occurred while processing the request. NodeInvocationException: Prerendering failed because of error: TypeError: $.extend is not a function */ } // Furthermore: if(false){ // <--FALSE // jQuery code here... /* But node thrown errors AGAIN! An unhandled exception occurred while processing the request. NodeInvocationException: Prerendering failed because of error: TypeError: Cannot set property 'serializeJSON' of undefined After I updated page second time, I've got: An unhandled exception occurred while processing the request. NodeInvocationException: Prerendering failed because of error: TypeError: $.extend is not a function */ } } ... } ` What should I do to prevent initialize scripts in server rendering and run it on client side only? I am using React + Redux starter kit.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#152
No description provided.