Skip to content
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

Unable to add styles #31

Open
greygatch opened this issue Jul 24, 2017 · 7 comments
Open

Unable to add styles #31

greygatch opened this issue Jul 24, 2017 · 7 comments

Comments

@greygatch
Copy link

greygatch commented Jul 24, 2017

module: {
    loaders: [
      {
        test: /\.js?/,
        loader: 'babel-loader',
        include: path.join(__dirname, 'app'),
      },
      {
        test: /\.scss$/,
        loader: 'style-loader!css-loader!sass-loader',
        include: path.join(__dirname, 'app')
      }
    ]
  }
SyntaxError: /Users/evan/code/universal-react/app/style.scss: Unexpected token, expected ; (1:5)
> 1 | body {
    |      ^
  2 |   text-align: center;
  3 | }

This project is apparently unable to allow for the addition of CSS modules via webpack

@jturbo26
Copy link

jturbo26 commented Jul 31, 2017

Hey @greygatch - I don't think it's this boilerplate's fault. You're only using a SCSS loader but you also need the CSS loader and the Style loader. The SCSS loader only converts SCSS to CSS, but webpack still needs to be able to read CSS.

@sekoyo
Copy link
Owner

sekoyo commented Jul 31, 2017 via email

@greygatch
Copy link
Author

greygatch commented Jul 31, 2017

@jturbo26 @dominictobias

You're only using a SCSS loader but you also need the CSS loader and the Style loader

I don't understand. Am I not chaining the loaders together and using all three?

loader: 'style-loader!css-loader!sass-loader',

This is an old style to use multiple loaders, but it is supported.

@sekoyo
Copy link
Owner

sekoyo commented Jul 31, 2017

Hm yeah I replied via email and didn't see the original post, looks correct so I'm not sure where the problem is, but there's nothing specific in this repo preventing it.

What's more likely is that this is the Node process encountering the scss import and Node doesn't know what to do with it. Try adding at the top of server.js:

require.extensions['.scss'] = () => {};

@jturbo26
Copy link

@greygatch Yep. My bad. I don't know how I didn't see that chain.

@greygatch
Copy link
Author

@jturbo26 Just to make sure it didn't break with the new webpack release, I updated it to the new way.

Maybe it has something to do with the universal rendering?

{
    test: /\.scss$/,
    use: [
         'style-loader',
         'css-loader',
         'sass-loader'
    ],
    include: path.join(__dirname, 'app')
}

@jturbo26
Copy link

I don't think it's the universal rendering because I was able to get css to load. Are you sure you've installed all your loaders with npm install?

I don't use SASS, but I was able to get CSS modules working very easily. Here's part of my webpack config to compare.

module: {
    rules: [
      {
        test: /\.js?$/,
        use: 'babel-loader',
        include: path.join(__dirname, 'app'),
      },
      { test: /\.jsx$/, use: 'babel-loader', exclude: /node_modules/ },
      {
        test: /\.css?$/,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: {
              modules: true,
              localIdentName: '[name]_[local]_[hash:base64:5]',
            },
          },
        ],
      },
    ],
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants