wepback 4.0.0 compatiblity
alexan opened this issue · 5 comments
hello,
this loader throws an exception when used with webpack 4.0.0
it throws:
ERROR in ./app/test.html
Module build failed: TypeError: Cannot read property 'htmlhint' of undefined
at Object.module.exports
Wondering if I need to install htmlhint as a devDep, require it in my webpack.config.js, point options.htmlhint to it...
I found the problem:
// index.js - line ~143
const options = Object.assign(
{ // Loader defaults
formatter: defaultFormatter,
emitAs: null, // Can be either warning or error
failOnError: false,
failOnWarning: false,
customRules: [],
configFile: DEFAULT_CONFIG_FILE
},
this.options.htmlhint || {}, // PROBLEM
loaderUtils.getOptions(this) // Loader query string
);this.options does not exist in that context as this.options hasn't actually
been defined yet.
If I remove this line from the Object.assign(), things work.
I'm not sure of the original intent of the line, so I'm weary to just remove it
in a pull request no questions asked.
@mattlewis92: I'll submit a pull request to remove it, but please let me know
the original intent here and I can update the PR if necessary.
Thanks!
I think this line is used to get user defaults from webpack.config:
const path = require('path');
module.exports = {
entry: "./app/entry",
htmlhint: {
user config
}
}
the loader migration guide states explicitly that this feature where deprecated in webpack 3.0.0
https://medium.com/webpack/webpack-4-migration-guide-for-plugins-loaders-20a79b927202
Guideline: Loaders should receive all options via this.query. They should not use other ways to receive options, i. e. no property in webpack options, no environment variable.
- maybe you should check if this.options is set in webpack 2-3 and log a dreprecation warning
- if options is not available ignore it
Fixed in 1.3.1 🎉
@mattlewis92 Thanks!