Next.js 和 Sass 出现错误提示“您可能需要适当的加载程序来处理此文件类型错误”

Next.js with Sass occurs on error saying " You may need an appropriate loader to handle this file type error"

我尝试了几次连接我的 next.js 和 scss,但它不起作用。

我想我已经设置好一切以使用 scss 编译我的文件。

错误说

/scss/style.scss 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
> .example {
|   color: blue;
| }

这是代码:

next.config.js

const withSass = require("@zeit/next-sass");
module.exports = withSass();

_document.js

import Document, { Head, Main, NextScript } from "next/document";

export default class extends Document {
  render() {
    return (
      <html>
        <Head>

        <link rel="stylesheet" href="/_next/static/style.css" />
        <Head />
        <body>
          <Main />
          <div id="modal" />
          <NextScript />
        </body>
      </html>
    );
  }
}

index.js

import "../scss/style.scss";

import axios from "axios";

const Index = props => {
  return (
    <div>
      <div className="example">hello</div>
      <header>
        <Header />
      </header>
      <section>
        <Body stores={props.data} />
      </section>
      <footer>
        <Footer />
      </footer>
    </div>
  );
};

style.scss 在 SCSS 文件夹中

.example {
  color: blue;
}

尝试将 import "../scss/style.scss"; 添加到您的 _document.js