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.

Uncaught TypeError: Cannot read property '0' of undefined

See original GitHub issue

No matter what I do, I can not get the map to actually render. The box itself renders, but is empty and this error mapbox-gl.js?31ef:295 Uncaught TypeError: Cannot read property '0' of undefined appears every time i move my mouse around where the map should be. The cursor changes, so the map box is there, just empty. Below is the component that renders it:

import React from "react"
import cssModules from "react-css-modules"
import style from "./style.css"
import { connect } from 'react-redux'
import ReactMapboxGl, { Layer, Feature } from "react-mapbox-gl"

const config = {
  containerStyle: {height: "100vh", width: "100vw"},
  accessToken: "....",
  style: "mapbox://styles/mapbox/streets-v9"
};

export class Map extends React.Component {
  render() {
    return (
      <div>
        <h1>Hello</h1>
        <ReactMapboxGl
          style={config.style}
          accessToken={config.accessToken}
          containerStyle={config.containerStyle}
        />
      </div>
    )
  }
}

const mapStateToProps = state => {
  return {
    user: state.user
  }
}

export default connect(mapStateToProps)(cssModules(Map, style))

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
alex3165commented, Aug 24, 2016

Should be fixed with the version 0.9.3 😃

1reaction
Harrisonlcommented, Aug 21, 2016

@alex3165 it’s a company project so most likely not sorry. I can probably add in the webpack and package.json file though if that helps? I’ll have to add them when I get home.

On a side, is there any other dependencies I need to get this working? I reduced the london example to pretty much the exact same lines of code and replicated the webpack file from the example and it works there. I can’t figure out what the difference between the two is.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Fix Cannot read Property '0' of Undefined in JS
The Solution · Ensure you are using the correct variable · Perform a simple check on your variable before using it to make...
Read more >
How to Prevent the Error: Cannot Read Property '0' of Undefined
If a property of an object is an array, it's possible to accidentally misspell the key or try to access the array through...
Read more >
TypeError: Cannot read Property '0' of Undefined in JS
The "Cannot read property '0' of undefined" error occurs when trying to access the 0th index in a variable that stores an undefined...
Read more >
Javascript Uncaught TypeError: Cannot read property '0' of ...
Javascript Uncaught TypeError: Cannot read property '0' of undefined ; If you want to find a letter in array, then (words.indexOf(letter) > 0) ......
Read more >
Fix: Cannot Read Property '0' of Undefined - Coding Beauty
The “cannot read property '0' of undefined” error occurs when you try to access the 0 index of an array-like variable, but the...
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