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.

Storybook: Cannot render the background image in CSS correctly

See original GitHub issue

Current Behavior

When using image file in module.scss, the background image cannot be displayed correctly in the storybook,

and the image file actually generated are damaged.

Expected Behavior

Can use the background image in module.css and show it.

Steps to Reproduce

Create a project

# 1.  create project
npx create-nx-workspace project-name --preset=next --style=scss --appName=app-name

# 2. generate libray, named `uikit`
nx generate @nrwl/react:library --name=uikit --style=scss --linter=eslint --unitTestRunner=jest --pascalCaseFiles --publishable --buildable --component --strict --no-interactive

# 3. add storybook to project
yarn add --dev @nrwl/storybook
nx g @nrwl/react:storybook-configuration uikit

Add some code and file

  1. add a image file into libs/uikit/src/lib folder, like libs/uikit/src/lib/demo.png

  2. modify libs/uikit/src/lib/Uikit.module.scss file, like:

.background {
  background: url('demo.png'); // add image to here
  background-size: 100%;
  width: 100px;
  height: 100px;
}
  1. modify libs/uikit/src/lib/Uikit.tsx file, like:
import s from  './Uikit.module.scss'; // modified
import { FC } from 'react';

export interface UikitProps {
  name: string;
}

export const Uikit: FC<UikitProps> = ({ name }) => {
  return (
    <div className={s.background}> // modified
      <h1>Welcome to Uikit! {name}</h1>
    </div>
  );
};

export default Uikit;

And finally execute the command to launch the StoryBook service

nx run uikit:storybook

Failure Logs

None

Environment

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
kaspar-naabercommented, Feb 4, 2022

It also appears to be happening in both - the Storybook and the react app as well.

It links to a SVG that is not rendering correctly: Storybook: Screen Shot 2022-02-04 at 12 40 13

Screen Shot 2022-02-04 at 12 36 41

React app (Next.JS) Screen Shot 2022-02-04 at 12 40 28

Screen Shot 2022-02-04 at 12 38 49
1reaction
kaspar-naabercommented, Mar 7, 2022

Still happens to me with the latest version of NX also. Are you sure that the SVG usage is also fixed? Because as far as I know you fixed using the PNG-s.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I configure Storybook.js Webpack to work with ...
I am having trouble configuring the Storybook.js webpack to be able to resolve these absolute image paths. For example, in a CSS module...
Read more >
Story rendering - Storybook
In Storybook, your stories render in a particular “preview” iframe (Canvas tab) inside the larger Storybook web application.
Read more >
Forums - CSS - [Solved] Background Image Not Showing
I have the background image saved in the images folder, obviously, as a jpeg. ... 3) The file is saved correctly.
Read more >
WordPress Background Images: How to Add, Edit ... - Kinsta
Make Sure the Background Images Are Sized Properly ... Select the Additional CSS tab in the WordPress Customizer. 'Additional CSS' section ...
Read more >
How To Make A Responsive Background Image Using CSS?
In this blog learn the importance of responsive background images for seamless user experience, css background image properties for making ...
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