storybook: Can't import css
I am trying to use storybook for the first time. In my project I am using blueprintJs as UI library so to test my components I need to import the css file for blueprint. According to the docs
CSS Support You can simply import CSS files wherever you want, whether it’s in the storybook config file, a UI component, or inside a story definition file.
Basically, you can import CSS like this:
// from NPM modules import ‘bootstrap/dist/css/bootstrap.css’;
// from local path import ‘./styles.css’; Note: this is plain CSS only. If you need a preprocessor like SASS, you need to customize the webpack config.
In the .storybook/config.js I added an import like this:
import { configure } from '@storybook/react';
import '@blueprintjs/core/dist/blueprint.css';
const req = require.context('../stories', true, /\.stories\.js$/);
function loadStories() {
req.keys().forEach(filename => req(filename));
}
configure(loadStories, module);
Unfortunatly that does not work and I got this error:
ERROR in ./node_modules/@blueprintjs/core/dist/blueprint.css
Module parse failed: /home/zied/projects/optimal-projects/optimal-compta-desktop/node_modules/@blueprintjs/core/dist/blueprint.css Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type.
| @charset "UTF-8";
| /**
| * Copyright 2015 Palantir Technologies, Inc. All rights reserved.
@ ./.storybook/config.js 5:0-47
@ multi ./node_modules/@storybook/react/dist/server/config/polyfills.js ./node_modules/@storybook/react/dist/server/config/globals.js ./node_modules/webpack-hot-middleware/client.js?reload=true ./.storybook/config.js
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 22 (8 by maintainers)
If I do this
it works for
style.css, but not for external module. So I have to include all the project, and addurl-loaderfor fonts:Things start working for me if I remove the empty webpack.config.js
Since Blueprint also imports fonts, this could by failing due to a
@font-faceCan you try adding file-loader or url-loader to your config?
(from https://github.com/webpack-contrib/css-loader/issues/38)
You can also try
rm -rf node_modulesthen reinstall.Otherwise there is this ongoing css-loader issue that might one day have answers - https://github.com/webpack-contrib/css-loader/issues/355
@zhsisusie I think it’s due to symlinking. If locally linked to the dependency, you don’t need the deeper include.
Ok, I wrapped it into create-react-app to make things simpler. The repo
@Hypnosphi , same error. I tried to copy the css file from the
node_modulesand put it in.storybookfolder and import it and the same result, It does not import any css file from any directory.