20 days ago · Tech · hide · 0 comments

node.js syntax checker bug about shadowing in private fields2026-06-24 · ChrisFinally understood an issue I was encountering, that in my opinion is a bug and super confusing and deceptive.SyntaxError: Private field must be declared in an enclosing class The gist is the following: let's say you declared a class and have a private field (#somePrivateMethod) there.class Example { #somePrivateMethod(param1) {} } node --check reports 👌 so all good so far.The issue arises when you write a very specific typo inside #somePrivateMethod, namely shadowing the private method parameters.e.g.class Example { someInstanceMethod () { this.#somePrivateMethod('test') } #somePrivateMethod(param1) { // unintentional shadowing through typo or clanker const param1 = '...' } } node --check now will report the following:tmp.js:3 this.#somePrivateMethod('test') ^ SyntaxError: Private field '#somePrivateMethod' must be declared in an enclosing class at wrapSafe (node:internal/modules/cjs/loader:1806:18) at…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.