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

Angular 16 runtime error Cannot set properties of undefined (setting 'black') at 91202 (tnp-core.mjs:471:34) #62

Open
Jahrenski opened this issue Sep 11, 2023 · 1 comment

Comments

@Jahrenski
Copy link

Jahrenski commented Sep 11, 2023

Hi!

I just migrated from angular 14 to angular 15 and then 16 while upgrading my packages but I get a runtime error when I include ng2-logger.

Uncaught TypeError: Cannot set properties of undefined (setting 'black') at 91202 (tnp-core.mjs:471:34)

I dug a little deeping and it seems to be caused by the "tnp-core lib/node-chalk-mock.ts" dependency declared for the ng2-logger project.

I target es2022 in tsconfig.

This is caused by something for target es2022 that generates this wrong code in tnp-core/lib/node-chalk-mock :

const allObj = {
    black(a) {
        console.log(a);
    },
    gray(a) {
        console.log(a);
    },
    red(a) {
        console.log(a);
    },
    green(a) {
        console.log(a);
    },
    italic(a) {
        console.log(a);
    },
    magenta(a) {
        console.log(a);
    },
    bold(a) {
        console.log(a);
    },
    underline(a) {
        console.log(a);
    },
};
const map = new Map();
const all = Object.keys(allObj).map(key => {
    map.set(allObj[key], key);
    return allObj[key];
});
for (let i = 0; i < all.length; i++) {
    const e1 = all[i];
    for (let j = 0; j < all.length; j++) {
        const e2 = all[j];
        e1.prototype[map.get(e2)] = e2;
    }
}

If I override ng2-logger to use tnp-config/[email protected], then it works.

"overrides": {
    "ng2-logger": {
      "tnp-config": "16.0.14",
      "tnp-core": "16.0.14"
    }
  },

Let me know if I can provide any more information!

@darekf77
Copy link
Owner

Hi @Jahrenski I will have a look on this today.

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

No branches or pull requests

2 participants