Webpack,sass-loader w/ node-sass 无法解析模块@import ("Unexpected character '@'")

Webpack, sass-loader w/ node-sass fails to parse module @import ("Unexpected character '@'")

概览: 我正在尝试使用带有 "node-sass"、"sass-loader"、"css-loader"、& "style-loader" 的 Webpack 编译 SCSS,除了作为 JS 转译器的 Typescript 之外,没有特定的 JS 框架。

我已经尝试了所有我能想到的或可以在 Internet 上找到的方法,包括安装我知道在其他项目中工作的这些依赖项的旧版本。在这一点上,我束手无策。谁能发现我做错了什么?

如果我需要添加更多详细信息,请告诉我。

观察到的错误:

ERROR in ./src/styles/base.scss 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 @import 'reset';

|

| /*

@ ./src/layouts/page.ts 21:0-30

@ ./app.ts

ℹ 「wdm」: Failed to compile.

package.json 详情:

Webpack 配置:

const path = require('path');
const CWD = process.cwd();
const sass = require('node-sass');
module.exports = {
    devtool: 'eval-source-map',
    devServer: {
        port: 4001
    },
    entry: {
        app: './app.ts'
    },
    output: {
        chunkFilename: '[id].js',
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].bundle.js',
    },
    mode: 'development',
    module: {
        rules: [{
            exclude: /node_modules/,
            test: /\.ts$/,
            loader: 'ts-loader'
        },
        {
            test: '/\.(css|scss)$/',
            use: [
                // Creates `style` nodes from JS strings
                'style-loader',
                {
                    // Translates CSS into CommonJS
                    loader: 'css-loader',
                    options: {
                        modules: true
                    }
                },
                {
                    // Compiles Sass to CSS
                    loader: 'sass-loader',
                    options: {
                        sassOptions: {
                            includePaths: [path.resolve(CWD, 'src/styles')]
                        }
                    }
                }
            ]
        }]
    },
    // Fixes npm packages that depend on `fs` module
    node: {
        fs: 'empty'
    },
    resolve: {
        extensions: ['.css', '.js', '.scss', '.ts'],
        modules: [
            'node_modules',
            path.resolve(__dirname)
        ]
    },
    target: 'web'
};

看起来你不小心引用了你的正则表达式:

- test: '/\.(css|scss)$/',
+ test: /\.(css|scss)$/,