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

The "sass" file extension doesn't work #5

Closed
Hubro opened this issue Feb 22, 2020 · 3 comments · Fixed by #6
Closed

The "sass" file extension doesn't work #5

Hubro opened this issue Feb 22, 2020 · 3 comments · Fixed by #6
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Hubro
Copy link
Contributor

Hubro commented Feb 22, 2020

I'm having issues with the sass support built in to Next.js (specifically vercel/next-plugins#149), so I decided to try your fix.

It doesn't seem to work though.

Here is my next.config.js:

const path = require("path");

const withStyles = require("@webdeb/next-styles");

module.exports = withStyles({
  pageExtensions: ["tsx"],

  webpack: config => {
    config.resolve.alias['~'] = path.resolve(__dirname) + "/src";
    return config;
  },

  // next-styles configuration
  sass: true,
  modules: true,
  sassLoaderOptions: {
    sassOptions: {
      includePaths: ["src/styles"], // @import 'variables'; # loads (src/styles/varialbes.scss), you got it..
    },
  },
  cssLoaderOptions: {},
  postcssLoaderOptions: {},
});

console.log("EXPORTED NEXT CONFIG:", module.exports);

(I added that last line in an attempt to check what next-styles added, but as it's all done in the webpack function it didn't help.)

Here is my src/pages/_app.tsx file:

import { AppProps } from "next/app";

// TODO: Import only what is used
import "bulma/bulma.sass";

function MyApp({ Component, pageProps }: AppProps) {
  return <Component {...pageProps} />
}

export default MyApp;

When I run the dev server, it's throwing an error as if I hadn't configured a loader at all:

[ info ]  waiting on http://localhost:3000 ...
EXPORTED NEXT CONFIG: {
  pageExtensions: [ 'tsx' ],
  webpack: [Function: webpack],
  sass: true,
  modules: true,
  sassLoaderOptions: { sassOptions: { includePaths: [Array] } },
  cssLoaderOptions: {},
  postcssLoaderOptions: {}
}
[ error ] ./node_modules/bulma/bulma.sass 1:0
Module parse failed: Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> @charset "utf-8"
| /*! bulma.io v0.8.0 | MIT License | github.com/jgthms/bulma */
| @import "sass/utilities/_all"
[ wait ]  compiling ...

Any idea what's wrong here? Did I mess something up, or doesn't next-styles work with this Next.js version?

@webdeb
Copy link
Owner

webdeb commented Feb 22, 2020

Thank you! Its because I forgot to add the "sass" extension support. "scss" should work.
I am on something else right now, do you like to take action and add support for sass files?

Check this lines:
https://github.com/webdeb/next-styles/blob/master/withStyles.js#L85-L86
https://github.com/webdeb/next-styles/blob/master/withStyles.js#L103

@webdeb webdeb added bug Something isn't working good first issue Good for newcomers labels Feb 22, 2020
@Hubro
Copy link
Contributor Author

Hubro commented Feb 23, 2020

Thank you! Its because I forgot to add the "sass" extension support. "scss" should work.
I am on something else right now, do you like to take action and add support for sass files?

Check this lines:
https://github.com/webdeb/next-styles/blob/master/withStyles.js#L85-L86
https://github.com/webdeb/next-styles/blob/master/withStyles.js#L103

Hmm... I replaced all instances of scss in patterns with s[ac]ss, and it seems to have somewhat worked. I can now import styles globally, and I can use modules, but only on the initial build.

As soon as I change anything that causes hot module replacement, I get this error:

image

This also happens if I just use scss...

If I just use css, everything works perfectly ☹️

@Hubro
Copy link
Contributor Author

Hubro commented Feb 23, 2020

Woopsie! My bad, turns out I need some extra TypeScript configuration to allow importing weird extensions like "scss" and "sass". Weirdly enough "css" worked by default though. Probably because of the references in next-env.d.ts.

Anyway, I just added these 2 lines to the bottom of next-env.d.ts and now everything appears to be working perfectly:

declare module "*.sass";
declare module "*.scss";

I'll make a pull request asap.

@Hubro Hubro changed the title Does this no longer work with next@9.2.1 The "sass" file extension doesn't work Feb 23, 2020
Hubro added a commit to Hubro/next-styles that referenced this issue Feb 23, 2020
@webdeb webdeb closed this as completed in #6 Feb 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants