css-loader: Module build failed: Unknown word (5:1)
When I try to load CSS like so require('css!./file.css');
I receive an error:
ERROR in ./~/css-loader!./file.css
Module build failed: Unknown word (5:1)
3 | // load the styles
4 | var content = require("!!./../../../node_modules/css-loader/index.js!./file.css");
> 5 | if(typeof content === 'string') content = [[module.id, content, '']];
| ^
6 | // add the styles to the DOM
7 | var update = require("!./../../../node_modules/style-loader/addStyles.js")(content, {});
8 | if(content.locals) module.exports = content.locals;
Content of the CSS file:
body {
}
Here is a complete sample: https://gist.github.com/desperate-man/50e522139734934b287382cf63e534af
However if I load the CSS file like this require('style!./file.css');
or this require('./file.css');
I have no errors. Is require('css!');
supposed to work or not? I use version 0.25.0.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 95
- Comments: 29 (6 by maintainers)
In my case, the problem was the order of the loaders. I changed this:
to this:
and it worked.
Actually here’s the problem, loaders are applied twice:
ERROR in ./~/css-loader!./~/style-loader!./~/css-loader!./index.css
Both webpack config and require string is applied when resolving. I think this is as designed.
Solution: either remove the loader from
require
or from thewebpack.config.js
.I had to do this instead:
@michael-ciniawsky don’t know about support in
webpack
1
. But inwebpack
2
you can useor with
import
/cc @michael-ciniawsky we can close this issue Also i am bad in documentation and very bad in documentation in english, maybe you can do PR with example in
README.md
about this 😄I have this exact same error in webpack2 + css-loader, adding !css-loader or !style-loader or not does not help at all. Does anyone know why it might be happening or what can cause this kind of error?
EDIT: Now I know, I was trying to use it with vue the wrong way: http://stackoverflow.com/questions/37031123/why-am-i-not-being-able-to-compile-sass-with-webpack
this worked for me
{ test: /\.scss$/, use: [ { loader: "style-loader" }, { loader: "css-loader", }, ] }
I had the same error, “style!” didn’t help though. I’m using Angular2 Webpack Starter, turned out the issue was caused by unmatching include/exclude directories in webpack.common.js (css to-string-loader) and webpack.dev.js (css style-loader). So the erroneous config was:
Exchanged that by:
I was also facing this issue with storybook webpack config , and before pushing the rules I do:
And then push my css-modules rules, inspired by https://github.com/storybookjs/storybook/issues/2320:
I was facing this issue with
storybook
webpack config , and instead of pushing rules I do :for me, I was repeating it twice like this.
I removed one of them and it worked.
So finally this.
I had the same promlem. I have looked through my package.json. The ‘babel-cli’ was installed. I uninstalled it. It helped.
{ test: /.scss$/, use: [ “style-loader” , “css-loader” ] } It worked for me
+1