[4] Webpack turns "this" to undefined in class definitions
See original GitHub issueDo you want to request a feature or report a bug?
Bug
What is the current behavior?
See https://github.com/webpack/webpack/issues/6357#issuecomment-360308225 and https://github.com/babel/babel/issues/7264
Webpack turns the method in this code:
import React from 'react'
class A {
constructor() {
this.b = 1
}
method(a = this.b) {
console.log(a)
}
}
into
method(a = undefined.b) {
console.log(a)
}
probably confusing the top-level with class-level. Curiously without the import (any import) it seems to be fine.
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
MacOS High Sierra, Node 9.4.0, Webpack 4 beta.0
Issue Analytics
- State:
- Created 6 years ago
- Comments:17 (7 by maintainers)
Top Results From Across the Web
'this' is undefined in JavaScript class methods - Stack Overflow
I just wanted to point out that sometimes this error happens because a function has been used as a high order function (passed...
Read more >Optimization - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >TS Playground - An online editor for exploring TypeScript and ...
Check for class properties that are declared but not set in the constructor. ... Enable error reporting when this is given the type...
Read more >webpack class extends value undefined is not a constructor or ...
It is possible you are creating some sort of circular dependency loop by the way you import external modules in index.js. But, it...
Read more >How to Read React Errors (fix 'Cannot read property of ...
This error usually means you're trying to use .map on an array, but that array isn't defined yet. That's often because the array...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ooflorent Has this fixed been released in current webpack version. My webpack version is 4.29.0 and the same thing happening to me. I have imported one of my project’s dependency i.e. jquery plugin and within that file in class definition they passed “this” alias for window but webpack turned that into “undefined”.
I’ve opened a PR with a fix. Everything should be back to normal once it would be merged.