loganfsmyth / babel-plugin-transform-decorators-legacy

A plugin for Babel 6 that (mostly) replicates the old decorator behavior from Babel 5
MIT License
817 stars 57 forks source link

undefined is not a constructor (evaluating 'new u') #79

Open Jujenji opened 6 years ago

Jujenji commented 6 years ago

Hey Guys,

Beforehand, im sorry if my Question is obsolete, as it is maybe solved somewhere else on this board, but im quite new to programming and GitHub as well, so i thought ill just ask straight forwardly.

My issue is the following. Im working in an JS - React Native Scenario where I wanted to create a log decorator for getting indepth logs from my functions (params, call of the function, return values etc.)

My decorator looks like this:

export default function log () {
  return function (target, name, descriptor) {
    const {value} = descriptor;
    descriptor.value = function wrapper (...args) {
      console.log('Function ' + name + ' called with these arguments', args);
      const result = value.call(this, ...args);
      console.log('Function ' + name + ' returned ' + result);
      return result;
    };
    return descriptor;
  };
}

So here is my Issue im facing:

When I test the application with the emulator (running react-native run-android) everything is working fine, the app is functional and I get all the logs I wanted.

As soon as I let it build into a release.apk tho it crashes on start before the Appregistry is even called with the Error Message: undefined is not a constructor (evaluating 'new u')

The legacy decorator is inside the production environment dependencies:

"dependencies": {
    "babel-plugin-transform-decorators-legacy": "^1.3.5",
    "babel-core": "^6",
    "babel-runtime": "^6.0.0",

If there is anything I could provide more to help you guys help me :D just tell me. Id be very happy if someone could provide some knowledge here.

Thanks a lot.

loganfsmyth commented 6 years ago

I don't think there's enough info here to answer this. What new is failing? What makes you think this is an issue with decorators? What are you decorating?

Jujenji commented 6 years ago

Hey logan, thanks so much for your fast reply. So the thing is, before implementing the decorator mentioned above everything works smoothly inside the emulator in a Test and in a production environment. Even after implementing and running the app in an test environment, like building a debug version, everything is running smoothly and I get the logs I need and the decorator works as expected. But as soon as I have a compiled version set for release, the app crashes on start with the error message stated.

To answer your questions: I am decorating functions only, as I only want them to be logged. Purposely for example getting to know if my backend calls are called and which params they got, and what their return value is.

For the other question tho, this is what gives me the headache. It literally is "new u" but "u" is not a Class or Object in my Code but is only existing inside the obfuscated Code when compiled and there are like way too many of those.

Is there anything I could provide you or would you have any idea from experience what could cause this?

Thank you and best regards from Germany

J