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.

glamorous: Cannot read property 'div' of undefined

See original GitHub issue

First: I created the same issue at Jest https://github.com/facebook/jest/issues/3374 because I don’t know if it’s TypeScript or Jest related. I hope anyone can help me out of this. I just copy the same text as in the Jest issue for simplicity.

Do you want to request a feature or report a bug?

I think this is a bug.

What is the current behavior?

 FAIL  build/test/client/bla.test.js
  ● foo

    TypeError: Cannot read property 'div' of undefined
      
      at Object.<anonymous>.test (build/test/client/bla.test.js:8:38)
      at process._tickCallback (internal/process/next_tick.js:109:7)

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

I’ve made a repo here. Just run yarn install && yarn test. In my webpack production build the code runs. It only crashes when I run it in Jest.

I believe it has anything to do that glamorous defines module and jsnext:main in their package.json and webpack evaluates the flags and can interpret the exports and imports correctly. The default main points to a CommonJS package. TypeScripts however transpiles my test code to

var glamorous_1 = require("glamorous");
...glamorous_1.default.div...

and crashes because .default does not exist. It should look like

var glamorous_1 = require("glamorous");
...glamorous_1.div...

So I am not sure if this is TypeScript or Jest related. But as webpack is doing everything right I think this is Jest related.

What is the expected behavior?

It should run the test.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

I set up a sample project where you can reproduce it easily.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
ds300commented, Apr 26, 2017

Thanks for the thorough report 😃 Can you try adding allowSyntheticDefaultImports: true to your tsconfig.json ?

1reaction
ds300commented, Apr 26, 2017

By the way: allowSyntheticDefaultImports does not modify the output. It is only available at compile time.

This is true of tsc, but ts-jest uses the setting to decide whether it needs to compile import statements with babel. Otherwise we can end up with the same errors you are seeing because jest requires commonjs module syntax while other targets require es6 module syntax e.g. react-native and rollup.

However, this does raise an interesting question as to whether we should add a ts-jest specific config setting for this feature, rather than using allowSyntheticDefaultImports. The two concepts are strongly related, but does one strictly imply the other?

Read more comments on GitHub >

github_iconTop Results From Across the Web

glamorous: Cannot read property 'div' of undefined · Issue #3374
I've made a repo here. Just run yarn install && yarn test . In my webpack production build the code runs. It only...
Read more >
How can I can show a div if an object doesn't have a value ...
1 Answer 1 · Thanks, I can see what this is trying to do but for some reason the button is now hidden...
Read more >
Why am I getting the error of “cannot set property of undefined ...
Let's say you did some kind of DOM query, looking for an element of class `.article_caption`. And you want to check some data...
Read more >
vuejs/vue - Gitter
If I'm using ...mapState('activeItem'), to get the active item and map it but that item is empty when the user starts the application...
Read more >
Easy To Read Divi Changelog - Free Resource Pee-Aye ...
Fixed JavaScript error Cannot read property et_slider_destroy of null that may have ... Editor were not migrated to Div Presets for the Divi...
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