我一直在看webpack如何使用车把的例子--装载机,但似乎没有一个能与webpack 4合作。
误差
ERROR in ./src/templates/property-list-item.hbs Module build failed: TypeError: Cannot read property 'handlebarsLoader' of undefined at getLoaderConfig (/Users/Sam/Desktop/mettamware/Public/js/node_modules/handlebars-loader/index.js:24:37) at Object.module.exports (/Users/Sam/Desktop/mettamware/Public/js/node_modules/handlebars-loader/index.js:32:15) @ ./src/property-list.js 5:0-58 40:23-31 @ ./src/app.js
当我在node_modeules/handlerbars-loader/index.js**,中查看时,冒犯的函数是**
function getLoaderConfig(loaderContext) {
var query = loaderUtils.getOptions(loaderContext) || {};
var configKey = query.config || 'handlebarsLoader';
var config = loaderContext.options[configKey] || {};
delete query.config;
return assign({}, config, query);
}My webpack.config.js
const path = require('path');
module.exports = {
entry: './src/app.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.hbs$/,
use: [{
loader: "handlebars-loader",
options: {
helperDirs: path.resolve(__dirname, "./src/helpers")
}
}]
}
]
},
node: {
fs: 'empty'
}
};如果有人能帮忙,我会非常感激的。我已经寻找了几个小时的解决方案,并尝试了很多事情,但什么也没有得到。
发布于 2018-03-20 17:46:38
在Webpack 4中,loaderContext.options已被loaderContext.rootConfig所取代。
此承诺已经被制作到handlebars-loader软件包中,以使其与Webpack 4兼容,但是这还没有发布。
目前,我已经卸载了handlebars-loader,并且正在使用这叉子。
以下步骤解决了我的问题:
运行这两个命令。
npm uninstall handlebars-loader
npm install @icetee/handlebars-loader
webpack.config.js**,中的替换**
loader: "handlebars-loader"与
loader: "@icetee/handlebars-loader"发布于 2018-03-02 19:59:28
也是在升级一个老webpack四…
显然,它以前可以在配置上设置自定义属性。那就是它正在寻找handlebarsLoader的地方。
当您在其上设置handleBarLoader属性时,它会发出此错误。
对于加载程序选项: webpack 2不再允许配置中的自定义属性。 应更新加载器,以便在module.rules中通过加载程序选项传递选项。 在更新加载器之前,可以使用LoaderOptionsPlugin将这些选项传递给加载程序:
plugins: [
new webpack.LoaderOptionsPlugin({
// test: /\.xxx$/, // may apply this only for some modules
options: {
handlebarsLoader: ...
}
})
]在我的例子中,现在就这样设置:
plugins: [
new webpack.LoaderOptionsPlugin({
options: {
handlebarsLoader: {}
}
})
]https://stackoverflow.com/questions/49056600
复制相似问题