I'm currently setting up Storybook to integrate with Next.js, Ant Design, Less, and TypeScript. In Next.js, images need to be stored in the public/
directory and linked using absolute paths for universal usage within the project. I am facing challenges in configuring the webpack of Storybook.js to resolve these absolute image paths.
For instance, within a CSS module:
.testImage {
background-image: url('/images/cucumber.png');
background-repeat: no-repeat;
background-size: contain;
height: 300px;
width: 300px;
}
However, Storybook encounters an error during build:
ERROR in ./common/layout/TestImage/TestImage.module.css (./node_modules/css-loader/dist/cjs.js??ref--15-1!./common/layout/TestImage/TestImage.module.css)
Module build failed (from ./node_modules/css-loader/dist/cjs.js):
Error: Can't resolve '/images/cucumber.png' in '/Users/gerritvanderlugt/Development/misc/storybook-issue/common/layout/TestImage'
... [error details]
at /Users/gerritvanderlugt/Development/misc/storybook-issue/node_modules/enhanced-resolve/lib/Resolver.js:285:5
@ ./common/layout/TestImage/TestImage.module.css 2:12-115 9:17-24 13:7-14 45:20-27 47:4-60:5 49:6-59:7 50:38-45 56:26-33 58:21-28 68:15-22
... [more errors follow] ...
I've experimented with file-loader
, url-loader
, and css-loader
without success. Any assistance on this matter would be highly appreciated!
Here's the GitHub repository where you can reproduce the issue by executing npm install
followed by npm run storybook
.