gpt4 book ai didi

webpack - "Module ' "+ loader.path + "' is not a loader webpack 错误

转载 作者:行者123 更新时间:2023-12-01 09:48:34 26 4
gpt4 key购买 nike

webpack 版本 - 2.3.2

节点版本-4.6.1

我遇到了这个奇怪的错误

    /home/ubuntu/workspace/node_modules/webpack/node_modules/loader-runner/lib/loadLoader.js:35
throw new Error("Module '" + loader.path + "' is not a loader (must have normal or pitch function)");
^

Error: Module '/home/ubuntu/workspace/node_modules/file/lib/file.js' is not a loader (must have normal or pitch function)
at loadLoader (/home/ubuntu/workspace/node_modules/webpack/node_modules/loader-runner/lib/loadLoader.js:35:10)
at iteratePitchingLoaders (/home/ubuntu/workspace/node_modules/webpack/node_modules/loader-runner/lib/LoaderRunner.js:169:2)
at runLoaders (/home/ubuntu/workspace/node_modules/webpack/node_modules/loader-runner/lib/LoaderRunner.js:362:2)
at NormalModule.doBuild (/home/ubuntu/workspace/node_modules/webpack/lib/NormalModule.js:179:3)
at NormalModule.build (/home/ubuntu/workspace/node_modules/webpack/lib/NormalModule.js:268:15)
at Compilation.buildModule (/home/ubuntu/workspace/node_modules/webpack/lib/Compilation.js:142:10)

我查看了github问题和答案。看起来我需要在所有使用的加载程序中添加 -loaders。但是,我已经在使用 -loaders。查看我的 webpack 配置

    var webpack = require("webpack");
var path = require("path");
var ExtractTextPlugin = require('extract-text-webpack-plugin');


module.exports = {
entry: {app: './src/app.js' },
output: {filename: 'public/build/bundle.js',
sourceMapFilename: 'public/build/bundle.map' },
module: {
loaders: [
{ test: /\.(js|jsx)$/, loader: 'babel-loader',options: {
presets: ['stage-0','react','es2015'],
plugins: ["transform-decorators-legacy","transform-class-properties"]
} },
{ test: /\.css$/, loaders: [ 'style-loader', 'css-loader' ] },
{ test: /\.(eot|svg|ttf|woff|woff2)$/, loader: 'file?name=public/fonts/[name].[ext]' },
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
{
loader: 'file-loader',
options: {
name: '[sha512:hash:hex].[ext]'
}
},
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: true,
mozjpeg: {
progressive: true
},
gifsicle: {
interlaced: true
},
optipng: {
optimizationLevel: 7
}
}
}
]
}
]
}
}

stackoverflow 上没有其他线程可以解决此问题。这就是为什么我必须打开一个新线程。

最佳答案

问题出在这一行:

{ test: /\.(eot|svg|ttf|woff|woff2)$/, loader: 'file?name=public/fonts/[name].[ext]' }

你有一个名为 file 的模块已安装,Webpack 正在尝试加载。因为它不是一个加载器,所以你得到了错误(AFAIK,对于任何加载器配置,Webpack 总是首先尝试按名称逐字加载模块,所以 file 在这种情况下,并且只有当模块不存在会通过附加 -loader 重试,所以 file-loader;但是,由于 file 存在,Webpack 认为已经找到正确的加载器模块)。

改成这样:

{ test: /\.(eot|svg|ttf|woff|woff2)$/, loader: 'file-loader?name=public/fonts/[name].[ext]' }

关于webpack - "Module ' "+ loader.path + "' is not a loader webpack 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43157481/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com