react-lazylog icon indicating copy to clipboard operation
react-lazylog copied to clipboard

ReferenceError: self is not defined

Open maxfouquet opened this issue 5 years ago • 7 comments

Hi,

I've the following stacktrace using lazylog component with Next.js and TypeScript support :

self is not defined
ReferenceError: self is not defined
    at Object.<anonymous> (D:\Developpement\web-security-analyzer\client\node_modules\react-lazylog\build\index.js:1:31979)
    at t (D:\Developpement\web-security-analyzer\client\node_modules\react-lazylog\build\index.js:1:415)
    at Object.<anonymous> (D:\Developpement\web-security-analyzer\client\node_modules\react-lazylog\build\index.js:1:47729)
    at t (D:\Developpement\web-security-analyzer\client\node_modules\react-lazylog\build\index.js:1:415)
    at Object.<anonymous> (D:\Developpement\web-security-analyzer\client\node_modules\react-lazylog\build\index.js:1:47638)
    at t (D:\Developpement\web-security-analyzer\client\node_modules\react-lazylog\build\index.js:1:415)
    at D:\Developpement\web-security-analyzer\client\node_modules\react-lazylog\build\index.js:1:777
    at D:\Developpement\web-security-analyzer\client\node_modules\react-lazylog\build\index.js:1:787
    at D:\Developpement\web-security-analyzer\client\node_modules\react-lazylog\build\index.js:1:143
    at Object.<anonymous> (D:\Developpement\web-security-analyzer\client\node_modules\react-lazylog\build\index.js:1:262)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)
    at Module.require (internal/modules/cjs/loader.js:650:17)

Reproduced with:

  • v3.0.0
  • v4.0.0
  • v4.2.0

React component:

import * as React from 'react'
import * as LazyLog from 'react-lazylog'

interface Props {}
interface State {}

export default class sqlmap extends React.Component<Props, State> {
  state: State = { }
  render() {
    return (<LazyLog url="http://localhost:5000/sqlmap.log" />)
  }
}

Any idea ?

maxfouquet avatar Jul 24 '19 13:07 maxfouquet

I also encountered this problem, very strange

d1y avatar Nov 21 '19 06:11 d1y

same here

digvan avatar Jan 26 '20 01:01 digvan

Interesting. Is it possible that self is not defined in Typescript?

helfi92 avatar Jan 29 '20 08:01 helfi92

In case anyone comes across this again. If you're trying to use this with an SSR tool like nextjs this component must be rendered client-side.

I solved this by using dynamic imports.

sourcec0de avatar May 03 '20 12:05 sourcec0de

Solved via React.lazy, but if somebody can look into it, would be cool! Env: Typescript + react-scripts (create-react-app)

const LazyLog = React.lazy(() => import('react-lazylog'));
...
<Suspense fallback="...">
  <div style={{ height: '200px', width: '100%' }}>
    <LazyLog text="this works" extraLines={1} enableSearch />
  </div>
</Suspense>

shmidt-i avatar May 06 '20 10:05 shmidt-i

For NextJS with React < 18 I used this and it worked great:

import dynamic from 'next/dynamic';
import { Suspense } from 'react';

const LazyLog = dynamic(() => import('react-lazylog').then((mod) => mod.LazyLog), {
  ssr: false,
});

Then use the component as normal:

<div className='col-12' style={{ height: '80vh' }}>
     <Suspense fallback={<div>Loading...</div>}>
        <LazyLog text={rawLogsRef.current ? rawLogsRef.current : '\r'} extraLines={1} enableSearch={true} caseInsensitive={true} />
     </Suspense>
 </div>

I hope that helps!

drumfreak avatar Nov 12 '22 21:11 drumfreak

This is fixed in my released fork to work in SSR libs like Next See: https://github.com/melloware/react-logviewer/issues/28

melloware avatar Jun 06 '24 01:06 melloware