Next js import scss error(ModuleParseError: Module parse failed: Unexpected character '?' (1:0))

2 sass reactjs next.js

我的问题是

当我在“ProjectFolder/components/header/Header.js”中导入如下所示的 scss 文件时

(该 Header.js 位于相同的“页面”目录 level.v )

import "../../public/assets/scss/_reset.scss";
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

引起这个错误..

我也像这样创建 next.config.js 。

// next.config.js setting
const withSass = require('@zeit/next-sass');
module.exports = withSass();
Run Code Online (Sandbox Code Playgroud)

还有我的 package.json

在此处输入图片说明

我听说“/”路径正在自动解析“公共”目录...

所以我也试过了

import "/assets/scss/_reset.scss";
Run Code Online (Sandbox Code Playgroud)

但同样的问题已发布..

我能知道为什么..?

感谢您的阅读:)

小智 6

我解决了这个问题!改变 next.config.js!

const withSass = require('@zeit/next-sass');
const withCSS = require("@zeit/next-css");
module.exports = withCSS(withSass({
    webpack(config, options) {
        config.module.rules.push({
            test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
            use: {
                loader: 'url-loader',
                options: {
                    limit: 100000
                }
            }
        });

        return config;
    }
}));

Run Code Online (Sandbox Code Playgroud)