Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class A cannot instantiate an object B that inherit from A #17239

Closed
imabot2 opened this issue May 22, 2023 · 2 comments · Fixed by #17233
Closed

Class A cannot instantiate an object B that inherit from A #17239

imabot2 opened this issue May 22, 2023 · 2 comments · Fixed by #17233

Comments

@imabot2
Copy link

imabot2 commented May 22, 2023

Bug report

What is the current behavior?

I try to write a class A that instantiate an object B that inherit from A?

I get the following error on runtime

a.js:3 Uncaught ReferenceError: Cannot access 'A' before initialization
    at Module.default (a.js:3:56)
    at eval (b.js:3:32)
    at ./src/js/b.js (bundle.425598c….js:723:1)
    at __webpack_require__ (bundle.425598c….js:1278:41)
    at eval (a.js:5:63)
    at ./src/js/a.js (bundle.425598c….js:712:1)
    at __webpack_require__ (bundle.425598c….js:1278:41)
    at eval (index.js:2:63)
    at ./src/js/index.js (bundle.425598c….js:821:1)
    at __webpack_require__ (bundle.425598c….js:1278:41)

If the current behavior is a bug, please provide the steps to reproduce.

I use 3 files:

index.js

import A from "./a.js";
let a = new A();
a.fct();

a.js

import B from "./b.js"
    
export default class A {
  constructor() {
    console.log ("a constructor")
  }
  fct() {
    this.b = new B();
  }
}

b.js

import A from "./a.js"
    
export default class B extends A {
  constructor() {
    console.log ("b constructor")
  }
}

What is the expected behavior?

It shouldn't trigger an error at runtime. Since this is technically possible in JS as prooven on this JSFiddle

Other relevant information:
webpack version: 5.82.0
Node.js version: 18.16.0
Operating System: Ubuntu 22.04
Additional tools: -

@alexander-akait
Copy link
Member

Fixed #17233, release will be in wednesday

@alexander-akait
Copy link
Member

alexander-akait commented May 22, 2023

Anyway, you will have problems ReferenceError: Cannot access 'A' before initialization, if you will use this code, you can try it without webpack in browser and will see the same

Or you don't provide full reproducible code...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants