ng2-logger
ng2-logger copied to clipboard
Angular 16 runtime error Cannot set properties of undefined (setting 'black') at 91202 (tnp-core.mjs:471:34)
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.
`-- [email protected]
`-- [email protected]
`-- [email protected]
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!