Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference Error: self is not defined

We are facing the issue

"Reference Error: self is not defined'

while trying to use React-data-grid. The issue is on the server side while trying to build the nodejs application using webpack. We are facing issue in the generated bundle file in the following lines

isOldIE = memoize(function() {          return /msie
[6-9]\b/.test(self.navigator.userAgent.toLowerCase());      }),

Could you let us know how can we fix this. It looks like the react data grid package has issues with the server side rendering.

like image 887
Rakesh Nallam Avatar asked Oct 25 '17 19:10

Rakesh Nallam


People also ask

How do you fix the error require is not defined?

To solve the "ReferenceError require is not defined" error, remove the type property if it's set to module in your package. json file and rename any files that have a . mjs extension to have a . js extension.

Is not defined reference error?

The Javascript ReferenceError occurs when referencing a variable that does not exist or has not yet been initialized in the current scope. The ReferenceError: event is not defined usually occurs while using an event handler if the event parameter is either not declared or declared incorrectly.

What is the meaning of reference error?

The #REF! error shows when a formula refers to a cell that's not valid. This happens most often when cells that were referenced by formulas get deleted, or pasted over.

What is JavaScript reference error?

The ReferenceError object represents an error when a variable that doesn't exist (or hasn't yet been initialized) in the current scope is referenced.


1 Answers

self is likely referring to window which is not available on the server side...it's only available in a browser context. The navigator reference makes this especially apparent. This code is trying to test the user agent for Internet Explorer verison.

self.navigator.userAgent.toLowerCase()

As Jordan pointed out, there is an open issue #361 regarding isomorphic rendering.

If possible, try to avoid executing that code when on the server-side. Otherwise, you'll have to wait for a patch in react-data-grid.

like image 154
styfle Avatar answered Sep 29 '22 06:09

styfle