当前位置: 首页 > 知识库问答 >
问题:

未找到模块:错误:无法在webpack.common.js中解析

南宫书
2023-03-14

当我执行npm运行构建时,我得到以下错误

找不到./src/assets/scss/theme.scss(./node_modules/css-loader/dist/cjs.js!./node_modules/resolve-url-loader!./node_modules/sass-loader/dist/cjs.js!./src/assets/scss/theme.scss)模块:错误:无法解析“../../../fonts/materialdesignicons-webfont.woff?v=4.4.95”在“

但如果我运行npm运行看着它正常工作

我的webpack.commom.js如下所示

const path = require('path')
const merge = require('webpack-merge')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const SetPublicPathPlugin = require('@rushstack/set-webpack-public-path-plugin').SetPublicPathPlugin

module.exports = merge({
    target: 'web',
    entry: {
        'profile-web-part': path.join(__dirname, '../src/webparts/profile/ProfileWebPart.ts'),
        'master-application-customizer-application-customizer': path.join(
            __dirname,
            '../src/extensions/masterApplicationCustomizer/MasterApplicationCustomizerApplicationCustomizer.ts'
        ),
        'list-data-web-part': path.join(__dirname, '../src/webparts/listData/ListDataWebPart.ts')
    },
    output: {
        path: path.join(__dirname, '../dist'),
        filename: '[name].js',
        libraryTarget: 'umd',
        library: '[name]'
    },
    performance: {
        hints: false
    },
    stats: {
        errors: true,
        colors: true,
        chunks: false,
        modules: false,
        assets: false
    },
    externals: [/^@microsoft\//, 'ProfileWebPartStrings', 'ControlStrings', 'MasterApplicationCustomizerApplicationCustomizerStrings', 'ListDataWebPartStrings'],
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                loader: 'ts-loader',
                options: {
                    transpileOnly: true
                },
                exclude: /node_modules/
            },
            {
                test: /\.(jpg|png|woff|woff2|eot|ttf|svg|gif|dds)$/,
                use: [
                    {
                        loader: '@microsoft/loader-cased-file',
                        options: {
                            name: '[name:lower]_[hash].[ext]'
                        }
                    }
                ]
            },
            {
                test: /\.css$/,
                use: [
                    {
                        loader: '@microsoft/loader-load-themed-styles',
                        options: {
                            async: true
                        }
                    },
                    {
                        loader: 'css-loader'
                    }
                ]
            },
            {
                test: function (fileName) {
                    return fileName.endsWith('.module.scss') // scss modules support
                },
                use: [
                    {
                        loader: '@microsoft/loader-load-themed-styles',
                        options: {
                            async: true
                        }
                    },
                    'css-modules-typescript-loader',
                    {
                        loader: 'css-loader',
                        options: {
                            modules: true
                        }
                    }, // translates CSS into CommonJS
                    'sass-loader' // compiles Sass to CSS, using Node Sass by default
                ]
            },
            {
                test: function (fileName) {
                    return !fileName.endsWith('.module.scss') && fileName.endsWith('.scss') // just regular .scss
                },
                use: [
                    {
                        loader: '@microsoft/loader-load-themed-styles',
                        options: {
                            async: true
                        }
                    },
                    'css-loader', // translates CSS into CommonJS
                    {
                        loader: 'resolve-url-loader'
                    },
                    'sass-loader' // compiles Sass to CSS, using Node Sass by default
                ]
            }
        ]
    },
    resolve: {
        extensions: ['.ts', '.tsx', '.js']
    },
    plugins: [
        new ForkTsCheckerWebpackPlugin({
            tslint: true
        }),
        new SetPublicPathPlugin({
            scriptName: {
                name: '[name]_?[a-zA-Z0-9-_]*.js',
                isTokenized: true
            }
        })
    ]
})

共有1个答案

郗福
2023-03-14

我可以通过使用resolve-url-loader模块来解决这个问题。它可以帮助某人下面是webpack.js的一部分

{
test: function (fileName) {
return !fileName.endsWith('.module.scss') && fileName.endsWith('.scss') // just regular .scss
},
use: [
{
loader: '@microsoft/loader-load-themed-styles',
options: {
async: true
}
},
{
loader: 'css-loader',
options: {
sourceMap: true
}
}, // translates CSS into CommonJS
'resolve-url-loader',
{
loader: 'sass-loader',
options: {
sourceMap: true
}
} // compiles Sass to CSS, using Node Sass by default
]
}
]
 类似资料:
  • 问题内容: 我正在使用Babel和Webpack开发一个React应用,我想使用npm中的软件包。我已经安装了该软件包并将其保存为项目的依赖项。运行npm start后,出现此错误: ./~/file-exists/index.js中的错误找不到 模块:错误:无法在C:\ GitHub \ CryptoPrices \ node_modules \ file-exists @ ./~/file-e

  • 我正在使用css加载程序,出现以下错误: 错误/src/pages/home/index。未找到js 模块:错误:无法解析“/Users/jian/Documents/sina/webpack barbarrian test”中的“css加载程序” @/src/pages/home/index。js 2:0-20 @multi/webpack barbarian/node_模块/webpack开发

  • 我使用本教程:https://alligator.io/vuejs/rest-api-axios/ 并尝试像这样使用axios:在我的main.js文件中: 在my.vue文件中: 错误。/node_modules/Babel-loader/lib!。/node_modules/vue-loader/lib/selector.js?type=script

  • 问题内容: 我不敢相信我在问一个明显的问题,但在控制台日志中仍然出现错误。 控制台表示无法在目录中找到该模块,但是我至少检查了10次错别字。无论如何,这是组件代码。 我想在根中渲染 Header 这是组件 我至少检查了10次该模块是否在此位置(文件夹“ header”包含“ header.js”)。 然而,React仍然抛出此错误: 编译失败 NPM测试 说的是同样的话。 问题答案: 我们通常使用

  • 我看到了类似的问题,但找不到解决办法,也许是因为我的webpack.config.js不同。重要的是要注意,我只得到这个问题在MacOS上执行"webpack--disport-erm-详情"的文件夹的根webpack.config.js. 完整的源代码在这里 网页包。配置。js 包裹json 完全错误 未找到输入模块中的错误:错误:无法在“/Users/Marvs/source/accountg

  • 试图使用放大身份验证创建React应用程序,遇到此错误 找不到模块:无法解决'@AWS-放大/核心'...\node_modules@aws-amplify\api\lib-esm' 我指的是这两个链接: https://dev.to/dabit3/the-complete-guide-to-user-authentication-with-the-amplify-framework-2inh h