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 access directly the style from style object

See original GitHub issue

After upgrading to 4.0.0 I have some issue with access to style object.

  • Previous version: 3.0.1
// This file is automatically generated.
// Please do not change this file!
interface CssExports {
  'container': string;
  'large': string;
  'medium': string;
  'small': string;
}
declare const cssExports: CssExports;
export = cssExports;

usage console.log(style.container);

  • Version: 4.0.0
// This file is automatically generated.
// Please do not change this file!
interface CssExports {
  'container': string;
  'large': string;
  'medium': string;
  'small': string;
}
export const cssExports: CssExports;
export default cssExports;

usage console.log(style.default.container);

Now I have to add one more key .default to access to the style object

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
PhillipWindercommented, Feb 18, 2020

I have the exact same issue as @tonyelewis

If I do

import * as styles from "./TabHeader.css";

the code works, but TypeScript throws errors.

If I do

import styles from "./TabHeader.css";

TypeScript is happy but the code does not work.

A downgrade from 4.0.0 to 3.0.1 fixes the issue but is obviously not a long term solution.

Anyway, thanks for the loader! 😃

0reactions
Liar0320commented, May 9, 2020

@tonyelewis When I was using it, I found similar problems, It will only be right the first time it works that import styles from "./xxxx" ,second import styles from "./xxxx" will wrong .

That’s how I do it. i find this issues esModule option behaviour

Solve in this file style-loader/src/index.js Line 28

// delete options.esModule; 

it will work right. But I didn’t find the reason why delete options.esModule in the code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why doesn't DOM style object set CSS variables directly?
It's because DOM's Style function only understands HTML properties and not CSS properties. Defining CSS properties are listed in style's ...
Read more >
Solving the React Error: Not Picking Up CSS Style | Pluralsight
In this guide, you will learn about the errors that can occur while importing a CSS file into your React file.
Read more >
HTMLElement.style - Web APIs | MDN
The style read-only property returns the inline style of an element in the form of a CSSStyleDeclaration object that contains a list of...
Read more >
Styling in React: 5 ways to style React apps - LogRocket Blog
So, instead of adding the styles inline directly, as we did in the previous example, we just pass the object variables as you...
Read more >
How to Style Your React App – 5 Ways to Write CSS in 2021
Inline styles are the most direct away to style any React application. ... For example, you cannot write animations, styles for nested ...
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