Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: Element is not defined #6610

Closed
fedorovsky opened this issue Mar 2, 2019 · 6 comments
Closed

ReferenceError: Element is not defined #6610

fedorovsky opened this issue Mar 2, 2019 · 6 comments

Comments

@fedorovsky
Copy link

fedorovsky commented Mar 2, 2019

/react-router-dom/cjs/react-router-dom.js:209
current: PropTypes.instanceOf(Element)

ReferenceError: Element is not defined

Version: 4.4.0-beta.7

@fedorovsky fedorovsky changed the title "react-router-dom": "4.4.0-beta.7", ReferenceError: Element is not defined Mar 2, 2019
@pshrmn
Copy link
Contributor

pshrmn commented Mar 2, 2019

Fixed by #6607

@timdorr
Copy link
Member

timdorr commented Mar 3, 2019

Just merged that in. Should be released soonish.

@timdorr timdorr closed this as completed Mar 3, 2019
@TotallWAR
Copy link

TotallWAR commented Mar 6, 2019

Is this fix in new version?
I can't see it fixed in version 4.4.0-beta.7 when install it with npm.

Now i manually paste var Element = typeof Element === "undefined" ? function () {} : Element; in node_modules/react-router-dom/cjs/react-router-dom.js at 208s

@taime
Copy link

taime commented Mar 12, 2019

It's NOT FIXED in 4.4.0-beta.7!!!

@mattcarlotta
Copy link

mattcarlotta commented Mar 12, 2019

The issue is that rollup removes unused code. It considers adding const Element = typeof Element === "undefined" ? function () {} : Element; as unused and unneccesary for the compiled source.

The crashing issue emanates from this line:

    PropTypes.shape({ current: PropTypes.any })

Using PropTypes.any seems to trigger a PropTypes.instanceOf(Element) validation call. Since Element is undefined, it crashes. A solution I'm currently using is to include a globally scoped Element variable:

modules/Element.js

const Element = typeof Element === "undefined" ? function() {} : Element;

export default Element;

Then including the file into

modules/index.js

export { default as Element } from "./Element";
export { default as BrowserRouter } from "./BrowserRouter";
export { default as HashRouter } from "./HashRouter";
export { default as Link } from "./Link";
export { default as NavLink } from "./NavLink";

Update: It looks the above isn't required. The error will be fixed in an up-and-coming release, however, the fix they've implemented is simpler:

  const toType = PropTypes.oneOfType([PropTypes.string, PropTypes.object]);
  const Element = typeof Element === "undefined" ? function() {} : Element;
  const innerRefType = PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.func,
    PropTypes.shape({ current: PropTypes.instanceOf(Element) })
  ]);

I've published a temporary fix in the meantime. Once react-router-dom is updated, do NOT use this fix.

@wmertens
Copy link
Contributor

@timdorr we're 2 weeks on, any chance of a beta.8 that fixes this?

@lock lock bot locked as resolved and limited conversation to collaborators May 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants