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.

Cannot read property 'addListener' of null

See original GitHub issue

Just trying a simple test of this library:

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import MediaQuery from 'react-responsive';

const toRender = (
  <div>
    <MediaQuery query='(min-device-width: 1224px)'>
      <div>YES</div>
    </MediaQuery>
  </div>
);

ReactDOM.render(
  toRender,
  document.getElementById('app'),
);

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1, shrink-to-fit=no">
    <title>Responsive Test</title>
  </head>
  <body style="background:#D3D3D3;">
    <div id="app"></div>
    <script type="text/javascript" src="/bundle.js"></script>
  </body>
</html>

I’m getting this error : Cannot read property 'addListener' of null

Looking into the code, it seems that the mq state of index is null by default.

Is there something I got wrong ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
yocontracommented, Jan 10, 2019

Library requires 16.3+ - you’ll get a warning on install if you have any version lower than that. Update to 16.3 and it should fix the problem.

0reactions
TimTim75commented, Jan 10, 2019

Nope 16.1.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'addEventListener' of null - Stack Overflow
On those pages where the function cannot find the id, I receive a "Cannot read property 'addEventListener' of null " error and none...
Read more >
Uncaught TypeError cannot read property 'addeventlistener' of ...
In JavaScript, a very common error is the Uncaught TypeError Cannot read property 'addeventlistener' of null. This error occurs when JavaScript is not...
Read more >
[SOLVED] Cannot Read Property 'addEventListener' of Null in ...
To fix the “cannot read property 'addEventListener' of null” error, make sure the selector used the access the element is properly defined.
Read more >
Cannot read property 'addEventListener' of Null in JS
The error "Cannot read property addEventListener of null" occurs when we call the addEventListener() method on a DOM element that doesn't exist.
Read more >
Cannot read property 'addEventListener' of null - JavaScript
I got this issue that I can't get passed. Tried to google it and searched on StackOverflow but still stuck.
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