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 'div' of undefined

See original GitHub issue

System:

  • OS: macOS High Sierra 10.13.6
  • CPU: (4) x64 Intel® Core™ i5-5257U CPU @ 2.70GHz
  • Memory: 428.57 MB / 16.00 GB
  • Shell: 3.2.57 - /bin/bash

Binaries:

  • Node: 8.11.4 - /usr/local/bin/node
  • Yarn: 1.12.3 - /usr/local/bin/yarn
  • npm: 6.5.0 - ~/.npm-global/bin/npm

npmPackages:

  • styled-components: ^4.1.3 => 4.1.3

Reproduction

This issue occurred once I have updated project dependencies:

-    "babel-eslint": "^8.2.6",
-    "babel-loader": "^7.1.5",
+    "babel-eslint": "^10.0.1",
+    "babel-loader": "^8.0.4",
-    "flow-bin": "^0.86.0",
+    "flow-bin": "^0.89.0",
-    "lint-staged": "^7.3.0",
+    "lint-staged": "^8.1.0",
-    "styled-components": "^4.1.1",
+    "styled-components": "^4.1.3",

Steps to reproduce

git clone https://github.com/kettanaito/atomic-layout
cd atomic-layout
git checkout dependencies
npm install
npm run storybook

You can see all the config files (babel, webpack, etc.) on the mentioned branch.

See the following exception thrown by Storybook.

Cannot read property 'div' of undefined
    TypeError: Cannot read property 'div' of undefined
    at Module.srcComponentsBoxJsx (http://localhost:6020/main.4a3566b995dd1c2ae279.bundle.js:2172:76)
    at __webpack_require__ (http://localhost:6020/main.4a3566b995dd1c2ae279.bundle.js:199:27)
    at Module.srcIndexJs (http://localhost:6020/main.4a3566b995dd1c2ae279.bundle.js:2815:60)
    at __webpack_require__ (http://localhost:6020/main.4a3566b995dd1c2ae279.bundle.js:199:27)
    at http://localhost:6020/main.4a3566b995dd1c2ae279.bundle.js:393:14
    at http://localhost:6020/main.4a3566b995dd1c2ae279.bundle.js:395:6
    at webpackUniversalModuleDefinition (http://localhost:6020/main.4a3566b995dd1c2ae279.bundle.js:143:898)
    at Module.<anonymous> (http://localhost:6020/main.4a3566b995dd1c2ae279.bundle.js:144:3)
    at Module../index.js (http://localhost:6020/main.4a3566b995dd1c2ae279.bundle.js:5381:30)
    at __webpack_require__ (http://localhost:6020/runtime~main.4a3566b995dd1c2ae279.bundle.js:782:30)

The following outputs undefined in the console:

import styled from 'styled-components'

console.log(styled)

I do acknowledge that this is most likely not an issue with the styled-components package. However, I would be very thankful for help, as I couldn’t find any relevant issues anywhere else.

Expected Behavior

  • styled can be imported as a default export of styled-components package

Actual Behavior

  • import styled from 'styled-components' resolves styled to undefined

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
mzalazarcommented, Apr 19, 2020

I was having the same error… i get rid of the selected code (in webpack.config.js):

Screenshot at 2020-04-19 07-43-23

and it worked for me =)

2reactions
altanycommented, Sep 18, 2019

I am facing the same issue as @kettanaito.

If I do const Element = styled.View I get this error: image

It seems I need to change all my declarations to

import { View } from 'react-native
const Element = styled(View)

to make it work but I really don’t want to do that, or downgrade my babel-loader.

Any ideas on how to fix this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: "cannot read property "div" of undefined" - Stack Overflow
The most likely reason this is happening is because you are iterating over the array with a value of 'i' that is larger...
Read more >
Uncaught TypeError: Cannot read property 'div' of undefined
Not Able to SEE METABOX and DIV which is visible by default in YOAST while editing the POST(or when we CLICK on SEO...
Read more >
How to Read React Errors (fix 'Cannot read property of ...
Cannot read property means the code was trying to read a property. This is a good clue! There are only a few ways...
Read more >
Cannot Read Property Length of Undefined in JavaScript
The JavaScript TypeError: Cannot read property 'length' of undefined occurs when the length property is read on an undefined variable.
Read more >
Cannot read property 'configure' of undefined - Funding Sources
This error occurs when a property is read or a function is called on an undefined variable. Undefined means that a variable has...
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