-
-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error compiling .scss file #69
Comments
I added a css-loader to the pipeline and the issue is now resolved. |
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 loaders: [
{
test: /\.scss$/,
loader: 'style!css!sass'
}
] index.scss body, html {
margin: 0;
padding: 0;
font-family: 'Helvetica', 'Arial', sans-serif;
color: #666;
} What did you do different? |
nm, I just fixed it, was missing the module object inside the webpack.config.js. Thanks! |
@danazkari Strange, I'm having the same issue as well and I do have the module object like so: var BrowserSyncPlugin = require('browser-sync-webpack-plugin'),
ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: './source/index.coffee',
output: {
filename: './app/bundle.js'
},
module: {
loaders: [
{test: /\.coffee$/, loader: 'coffee'},
{test: /\.scss$/, loader: ExtractTextPlugin.extract('css!sass'), include: './source/scss'}
]
},
plugins: [
new BrowserSyncPlugin({
host: 'localhost',
port: 9000,
server: {baseDir: ['./app']}
}),
new ExtractTextPlugin('./app/bundle.css', {
allChunks: true
})
]
} body {
background: red;
color: #fff;
} |
I have the same problem here. 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. const config = {
devtool: "source-map",
entry: [
`webpack-dev-server/client?http://${host}:${port}`,
"webpack/hot/only-dev-server",
"./src/client.js"
],
output: {
filename: "bundle.js",
chunkFilename: "[name].bundle.js",
path: dist,
publicPath: `http://${host}:${port}/dist/`
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ["react-hot", "babel?cacheDirectory"]
},
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
},
{
test: /\.(jpe?g|png|gif|svg)$/,
loader: "file"
}
]
},
sassLoader: {
includePaths: [path.resolve(__dirname, "../style")]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("development"),
BROWSER: JSON.stringify(true)
}
}),
new WebpackErrorNotificationPlugin()
]
}; And I try to import it like that. import '../../style/utils/normalize.scss'; And I get that error. SyntaxError: /Users/rparent/Documents/CTSProjects/arsenal/cms/application/app/style/utils/normalize.scss: Unexpected token (9:5)
7 | */
8 |
> 9 | html {
| ^
10 | font-family: sans-serif; /* 1 */
11 | -ms-text-size-adjust: 100%; /* 2 */
12 | -webkit-text-size-adjust: 100%; /* 2 */ |
Would be great if you guys could post a solution once you found it 👍 |
I managed to make it work with the ExtractTextPlugin. It makes a big bundle of all required stylesheet (I think) and then makes it available for the server-side rendering. Might not be the best way but it definitely work. |
@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. |
@seanwash Yes, please do show the code!! :) I fixed the error on the first post by adding It compiles just fine to JS, but I still don't have the CSS file.
Any ideas guys? |
Experiencing the same problem, not exactly sure what the problem is but it looks like the
|
I had the same issue, and somehow... I insist on "somehow", I fixed it by changing my loader from And here comes the mesmerizing part: I changed it back to |
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 So I fixed it by putting this code into my server-only file
|
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. |
I had the same problem, and for me solution was pretty simple. Webpack using different conf file for tests and there was no loaders for css|scss files. Hope it helps somebody. |
why. no one. shows. a solution with code. -_- |
This is what works for my module: {
loaders: [
{
test: /\.(less|css)$/,
include: /resources/,
loaders: [
'style?singleton',
ExtractTextPlugin.extract(`css?${JSON.stringify({
// sourceMap: DEBUG,
// CSS Modules https://github.com/css-modules/css-modules
// modules: true,
// camelCase: true,
// localIdentName: DEBUG ? '[name]_[local]_[hash:base64:3]' : '[hash:base64:4]',
// CSS Nano http://cssnano.co/options/
minimize: !DEBUG,
calc: false,
})}`),
'postcss',
'less',
]
},
]
},
plugins: [
new ExtractTextPlugin('style.min.css'),
] NoteI use |
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
Chrome dev has this error message:
Any tips on what I might be doing wrong? |
@msuzoagu I'm in the exact same situation. |
Also I, Someone found solution? |
@fxlemire your solution somehow worked for me too. Thanks! |
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. |
never mind. was completely my bad. |
I fixed this issue in
|
I have met the same problem, and it is caused by passing wrong params to module: {
loaders: [{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader", "sass-loader")
}]
} and I have solved it by doing this: module: {
loaders: [{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader", "css!sass")
}]
} |
This config fixed problem with include path for me:
|
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 double check ALL your keywords! |
@sampeka I have the exact same problem you had. Did you solve the problem? |
I'm still not seeing a fix here that works for me. |
This worked for me and ETP is ExtractTextPlugin. The issue i had was that the file name was wrong. Silly issue 👍 |
Explicitly excluding
If you have to include |
Update: My issue was odd. It was actually a GitHub lost commit unrelated to the project, but with identical results. |
If someone like me still needing this information this is my webpack.config file @chandu gave the idea how to solve it. Thanks. |
@erik-sn solution solved for me. For the ones who are lazy and do not want to go to Stackoverflow, here follows. Basically, just set in your webpack config for client side: plugins: [
new webpack.DefinePlugin({
'process.env.BROWSER': JSON.stringify(true),
})
], Then, in the component that is being rendered on server side, just test: if (process.env.BROWSER) {
require('./MyStyle.scss');
} Solved for me. Hope it helps. :) |
Setting up an existing codebase and facing the same issue, Tried everything but its not working. node version - Following is the webpack config snippet const cssLoader = !config.compiler_css_modules
? 'css?sourceMap'
: [
'css?modules',
'sourceMap',
'importLoaders=1',
// 'localIdentName=[name]__[local]___[hash:base64:5]',
'localIdentName=[local]',
'outputStyle=expanded'
// includePaths[]= + encoreURIComponent(paths.base('app','styles')) ?
].join('&');
webpackConfig.module.loaders.push({
test: /\.scss$/,
include: /app/,
loaders: [
'style',
cssLoader,
'postcss',
'sass'
]
});
webpackConfig.module.loaders.push({
test: /\.css$/,
include: /app/,
loaders: [
'style',
cssLoader,
'postcss'
]
});
// Don't treat global SCSS as modules
webpackConfig.module.loaders.push({
test: /\.scss$/,
exclude: /app/,
loaders: [
'style',
'css?sourceMap',
'postcss',
'sass'
]
});
// Don't treat global, third-party CSS as modules
webpackConfig.module.loaders.push({
test: /\.css$/,
exclude: /app/,
loaders: [
'style',
'css?sourceMap',
'postcss'
]
});
webpackConfig.sassLoader = {
includePaths: paths.client('styles'),
outputStyle: 'expanded'
};
webpackConfig.postcss = [
cssnano({
sourcemap: true,
autoprefixer: {
add: true,
remove: true,
browsers: ['last 2 versions']
},
safe: true,
discardComments: {
removeAll: true
}
})
]; |
npm install sass-loader node-sass webpack --save-dev this will working fine. |
Any body visiting this page in 2018, this piece of code made it work for me.
|
It works for me: |
I am looking for your solution 2 years later. Why to bother to add it!? Important it was that you was able to fix it. Oh God |
|
@toJanhonen I tried that fix (commenting out the include property, and now it works perfectly again. Quick snippet |
I am trying to compile
.scss
files using this loader.I am getting the error below when I invoke
webpack
command: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.Am pretty sure I am doing something wrong, but not sure what it is.
Can anyone help me with this?
The text was updated successfully, but these errors were encountered: