node-server icon indicating copy to clipboard operation
node-server copied to clipboard

Issue with RequestError having static name property

Open GavinMeierSonos opened this issue 1 year ago • 2 comments

Hard to say if this is a rollup issue or if this is a valid concern but the fix would be easy to implement.

When transpiling into esm. There is an issue with name being defined as a static value on the RequestError instead of just having it defined in the in the constructor. It throws an error saying that read only property name cannot be reassigned.

Happy to open a PR if this would be approved since it wouldn't impact any existing functionality and it does seem odd to define a static field on a class that is defined on the prototype. The fix would be to move the name assignment to the constructor after the super is called.

GavinMeierSonos avatar May 14 '24 20:05 GavinMeierSonos

Hi @GavinMeierSonos

Can you share the details to understand more easily or share the project to reproduce it?

yusukebe avatar May 15 '24 02:05 yusukebe

When this module is transpiled using swc, the output contain things like this:

let _getResponseCache;
var _class, _body, _init;
var RequestError = (_class = class extends Error {
    constructor(message, options){
        super(message, options);
    }
}, _class.name = "RequestError", _class);

And when it is evaluated in strict mode, following error occurs.

TypeError: Cannot assign to read only property 'name' of function 'class extends Error {
     constructor(message, options){
         super(message, options);
     }
}

HelloWorld017 avatar Dec 01 '24 05:12 HelloWorld017

I have the same error when use swc

himself65 avatar May 21 '25 18:05 himself65

change target to "target": "esnext" in tsconfig will workaround this

himself65 avatar May 21 '25 18:05 himself65

Hi @himself65

I'm not so faminiro to swc. I've tried but it does not throw an error. Can you share the instructions to reproduce it?

yusukebe avatar May 21 '25 23:05 yusukebe

https://play.swc.rs/?version=1.11.29&code=H4sIAAAAAAAAA02MQQqDQAxF954iOxU8gVC66gV6g2EaZGhNpkmGCsW7N44WzCLwfl4%2BLpnFIL6CKtzxXVDtJsICuBjSQ2GnbwOgFixFoDAjXKA9262fI5OalGgsnSPAjKphwtEfJdE01JCzJRevY63cJoai6FzoSfyhmq6%2B%2B8PQklG6o2z4F%2FTNZq0%2FGIkI7sAAAAA%3D&config=H4sIAAAAAAAAA1WPSw7DIAxE9zkF8rqLikUXvUMPgagTUfETdqSiKHcvJEDbHZ5h%2FMbbJAS8SMNdbOVZhqgSYRpzUSh7Vu%2BiAOeIpJOJDJfuMlVrVpbwkPbTAVZpQa4pJHmVsiXAhkBYZE4rNskZb%2Bb8i9TBxYREffOgOeUXi%2F%2FAqUHBhed6mO2UWvcscIPvpw4bi8HQoydrq2n%2FALtj80kWAQAA

himself65 avatar May 22 '25 09:05 himself65

@himself65 Thanks!

yusukebe avatar May 22 '25 22:05 yusukebe