I have a node.js backend project, and I use webpack
to build it.
"webpack": "^4.46.0",
"webpack-cli": "^4.4.0"
it reports error like
Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: this.getOptions is not a function
Then I read the source code of /node_modules/babel-loader/lib/index.js
to figure out why.
As you can see in the screenshot, there's only one search result of this.getOptions()
in the node_modules/babel-loader/lib/index.js
file. No definition of the function and it just be used. It's supposed to be a bug, at least it looks like that.
Why does the babel team
write souce code like that? And why do all others think it's a version conflict but not a code bug itself?
See getOptions method for Loaders
Webpack 5 ships with built-in
this.getOptions
method available in loader context. This is a breaking change for loaders that had been usinggetOptions
method from previously preferredschema-utils
:
this.getOptions
is available since Webpack 5
babel-loader
9.x supports webpack 5.x, since it uses this.getOptions
If you want to use webpack 4.x, then you should use babel-loader
8.x which supports webpack 4.x or 5.x. babel-loder
8.x uses loaderUtils.getOptions(this)
The version compatibility instructions are very clear on the readme
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With