question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Element` is not defined during server-side rendering

See original GitHub issue

Hello!

I get this error with version 4.0.0-rc.1.

…/node_modules/react-bootstrap-typeahead/lib/core/Overlay.js:46 referenceElement: _propTypes[“default”].instanceOf(Element) ^

ReferenceError: Element is not defined at Object.<anonymous> (…/node_modules/react-bootstrap-typeahead/lib/core/Overlay.js:46:54) at Module._compile (internal/modules/cjs/loader.js:738:30) at Object.Module._extensions…js (internal/modules/cjs/loader.js:749:10) at Module.load (internal/modules/cjs/loader.js:630:32) at tryModuleLoad (internal/modules/cjs/loader.js:570:12) at Function.Module._load (internal/modules/cjs/loader.js:562:3) at Module.require (internal/modules/cjs/loader.js:667:17) at require (internal/modules/cjs/helpers.js:20:18) at Object.<anonymous> (…/node_modules/react-bootstrap-typeahead/lib/components/Typeahead.react.js:26:39) at Module._compile (internal/modules/cjs/loader.js:738:30)

My implementation looks like this: …

    public render(): JSX.Element {
        const options = [
            { id: 0, firstName: 'Jon0', lastName: 'Doe0' },
            { id: 1, firstName: 'Jon1', lastName: 'Doe1' },
            { id: 2, firstName: 'Jon2', lastName: 'Doe2' },
            { id: 3, firstName: 'Jon3', lastName: 'Doe3' },
        ];
        return <AsyncTypeahead
            isLoading={this.state.isLoading}
            labelKey={option => `${option.firstName} ${option.lastName}`}
            onSearch={(query) => {
                this.setState({ isLoading: true });
                if (this.hTimeout) {
                    clearTimeout(this.hTimeout);
                }
                this.hTimeout = setTimeout(() => {
                    this.setState({
                        isLoading: false,
                        options,
                    });
                }, 3000);
            }}
            options={this.state.options}
        />
    }

Anyone else gets this? I am using react-bootstrap 1.0.0-beta.16 and @types/react-bootstrap-typeahead 3.4.5. Can that be it?

Cheers!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ericgiocommented, Feb 28, 2020

Thanks again for the report @Phrensoua. This should be fixed in v4.0.0-rc.2

0reactions
ericgiocommented, Feb 27, 2020

PropTypes.element & PropTypes.elementType actually aren’t appropriate here. I think something more generic like PropTypes.object is probably the way to go.

Edit: Looks like shimming Element might be the way to go:

Element = typeof Element === 'undefined' ? () => {} : Element;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular SSR - ReferenceError: Element is not defined
This library is using another JavaScript library (the "core" package) which isn't designed for server-side rendering. While you might be able to ...
Read more >
Angular SSR: ReferenceError: Element is not defined #1315
Describe the bug. I'm trying to enable SSR on my Angular project with SAP Spartacus, but when i instance with 'new AdyenCheckout(config)' and...
Read more >
How to solve Next.js window is not defined
An easy solution to resolve this issue is to rely on the useEffect , conveniently hooks aren't run when doing server-side rendering. Wrapping ......
Read more >
Solve “document is not defined” errors in Next.js | by WebTutPro
This way your component won't even be rendered on the server-side at all. import dynamic from "next/dynamic"; const Scroll = dynamic( () =>...
Read more >
How to fix ReferenceError: Document is not defined ... - Sabe.io
In this post, we looked at the most common reasons that causes the document reference error in JavaScript. The main culprits are using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found