Storybook: Cannot render the background image in CSS correctly
See original GitHub issueCurrent 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
-
add a image file into
libs/uikit/src/lib
folder, likelibs/uikit/src/lib/demo.png
-
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;
}
- 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
- Node.js: 14.18.2
- @nrwl/cli: 13.1.2
- @nrwl/storybook: 13.4.1
- @storybook/builder-webpack5: 6.3.12
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
React app (Next.JS)
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.