首页 > 解决方案 > 未找到模块:错误:无法解析 './foo/foo.scss' in

问题描述

我无法将我的 scss 文件导入到我的 tsx 文件中。我收到以下错误:

./wwwroot/clientapp/components/technology/technology.tsx 中的错误模块未找到:错误:无法解析 'C:\Repo\hobby\01.Code\Core\wwwroot 中的 './technology/technology.scss' \clientapp\components\technology' @ ./wwwroot/clientapp/components/technology/technology.tsx 3:0-38 @ ./wwwroot/clientapp/app.tsx npm 错误!代码 ELIFECYCLE npm 错误!errno 2 npm 错误!asp.net@1.0.0 构建:webpack npm 错误!退出状态 2 npm ERR!npm 错误!在 asp.net@1.0.0 构建脚本中失败。npm 错误!这可能不是 npm 的问题。上面可能有额外的日志输出。

我的网络包:

        {
            test: /\.scss$/,
            use: [
                { loader: "style-loader" },
                {
                    loader: "typings-for-css-modules-loader",
                    options: {
                        namedexport: true,
                        camelcase: true,
                        modules: true
                    }
                },
                { loader: "sass-loader" }
            ]
        },

在新文件夹类型下添加了声明文件:

declare module '*.css' {
    const content: { [className: string]: string; };
    export default content;
}
declare module '*.scss' {
    const content: { [className: string]: string; };
    export default content;
}

然后导入:

import './foo/foo.scss';

当我这样做时,npm run build我收到上述错误。

标签: webpacksass

解决方案


如果您从错误消息中更改导入

'./technology/technology.scss'

'./technology.scss'

它应该可以工作,你能检查一下吗?


推荐阅读