sass-loader: Error compiling .scss file
I am trying to compile .scss
files using this loader.
I am getting the error below when I invoke webpack
command:
Hash: 471ab211129c4252e031
Version: webpack 1.7.3
Time: 52ms
+ 1 hidden modules
ERROR in ./dummy.scss
Module parse failed: /home/chandu/www/sass-loader-test/node_modules/sass-loader/index.js!/home/chandu/www/sass-loader-test/dummy.scss Line 1: Unexpected token {
You may need an appropriate loader to handle this file type.
| body {
| background-color: #fff; }
|
I have created a repo to replicate the issue: https://github.com/Chandu/sass-loader-test
When I use node-sass directly I don’t get any error. You can try this running node test.js
from the repo linked above.
chandu@nobuntu:~/www/sass-loader-test$ node test.js
body {
background-color: #fff; }
Am pretty sure I am doing something wrong, but not sure what it is. Can anyone help me with this?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 7
- Comments: 42
Would be great if you guys could post a solution once you found it 👍
why. no one. shows. a solution with code. -_-
nm, I just fixed it, was missing the module object inside the webpack.config.js. Thanks!
I added a css-loader to the pipeline and the issue is now resolved.
Had the same issue, it turned out that it was Node who was throwing error but not Webpack since I’m running my code on both server and client. And Node, of course, doesn’t know what to do with
.scss
filesSo I fixed it by putting this code into my server-only file
I have met the same problem, and it is caused by passing wrong params to
ExtractTextPlugin
:and I have solved it by doing this:
Explicitly excluding
node_modules
was the solution for me.If you have to include
node_modules
for specific css files like Bootstrap or Toastr, then either@import
the css files into yourstyles.scss
or create a separate loader with them specifically for/\.css$/
files that includesnode_modules
.HI! I am having a bit of a problem getting sass-loader working properly. Current structure of project (as it relates to sass configuration):
webpack.config.dev.js
now in stylesheets/main.scss, I have the following:
When I run
npm start
I expect the styles instylesheets/main.scss
to be available in app but rather I get the error:Chrome dev has this error message:
Any tips on what I might be doing wrong?
Experiencing the same problem, not exactly sure what the problem is but it looks like the
scss
file is being treated like a javascript module even though there are loaders in place.This is what works for my
.less
Note
I use
webpack@2.1.0-beta.21
andextract-text-webpack-plugin@2.0.0-beta.4
I had the same issue, and somehow… I insist on “somehow”, I fixed it by changing my loader from
loader: 'style!css!sass'
toloaders: ["style", "css", "sass"]
.And here comes the mesmerizing part: I changed it back to
loader: 'style!css!sass'
and it still worked… somehow…I have the same problem here. @seanwash Did you manage to make it work?
This works on the client though. But every time I refresh, there’s a glitch before css is loaded because webpack is building the file, which is not exactly what I want.
And I try to import it like that.
And I get that error.
hey @Chandu I have the same issue right now and I do have installed the css-loader installed and it’s in the pipeline.
webpack.config.js
index.scss
What did you do different?
I just want to let you all know that I had this exact same problem. In my case it turns out that I had a typo. I had
modules
instead ofmodule
double check ALL your keywords!
@LoicUV and @Bosper: commenting out:
got everything working. Not sure why but thought it might be helpful for you both to know.
I’m not sure if everyone above was in the same situation, but I ran across this issue trying to do Isomorphic/Server Side rendering for React.
@ilearnio’s solution didn’t work for me - however the problem is definitely Node. Basically the wrinkle is that Webpack does its magic by looking for require/imports. So you must require/import the .scss file - however if you are doing Isomorphic/Server Side rendering, Node does not know what these .scss or even .css files are and has no webpack to help it, and you end up with a lot of “Unexpected Token” errors.
I followed the solution described here: and it worked well. Basically you declare the process.env.BROWSER variable in webpack, and conditionally require your .scss files on the client side if this variable exists. You also delete it at the beginning of your server.js file so it does not exist - so the server side code will not try to import it.
If someone like me still needing this information this is my webpack.config file @Chandu gave the idea how to solve it. Thanks. I’m using webpack 2.2 and extract-text-plugin@beta (^2.0.0-rc.3)
@raphaelparent wow I don’t know how I missed your reply! Sorry about that.
I also solved this problem with the extract text plugin, then I require the css file at the top of of main is file. I can post the code if anyone needs.
@fxlemire your solution somehow worked for me too. Thanks!
Any body visiting this page in 2018, this piece of code made it work for me.
I fixed this issue in
webpack@2.1.0-beta.25
by passing a value forincludePaths
…as @MsUzoAgu stated, include and/or exclude statements break this loader. i do not understand why this issue is closed. what am i missing here?
being able to include and exclude certain files is vital in my setup, so the workaround of removing the statement(s) is not really doing it for me. just to clarify, i would like to understand if this is a bug, or desired behaviour of this loader.
@seanwash Yes, please do show the code!! 😃
I fixed the error on the first post by adding
!css
torequire('css!./stylesheets/main.scss');
Took me about 4h to figure this out… phew.It compiles just fine to JS, but I still don’t have the CSS file. So I’m trying to setup the ExtractTextPlugin, and I’ve come across this:
ERROR in ./~/css-loader!./src/stylesheets/main.scss Module build failed: CssSyntaxError: /css-loader!/Users/...
Any ideas guys?
@danazkari Strange, I’m having the same issue as well and I do have the module object like so: