wallabyjs / console-ninja

Repository for Console Ninja questions and issues
https://console-ninja.com
Other
385 stars 22 forks source link

[Bug]: console.error not working in nestjs #336

Closed rugo83 closed 2 months ago

rugo83 commented 2 months ago

What happened?

image

Version

v1.0.355

CLI command to start your dev tool

pnpm run start:dev

Steps to reproduce (or sample repo)

nest new

Log output

22:23:50.890 info buildHook-52665 installing build hook for nest.js at /users/xxx/documents/nest-app-20240903, node v20.15.0
22:23:50.894 info buildHook-52665 allowed tools: vite, angular, jest, webpack, next.js, nest.js, cypress, http-server, serve, live-server, nuxt, remix, qwik, hydrogen, serverless, astro, node
22:23:50.894 info buildHook-52665 running tools: nest.js
22:23:50.896 info buildHook-52665 installing fs interceptor
22:23:51.006 info host client connected: buildHook { address: '127.0.0.1', family: 'IPv4', port: 63624 }
22:23:51.008 info buildHook-52665 allowed tools: vite, angular, jest, webpack, next.js, nest.js, cypress, http-server, serve, live-server, nuxt, remix, qwik, hydrogen, serverless, astro, node
22:23:51.008 info buildHook-52665 running tools: nest.js
22:23:51.489 info buildHook-52665 file processed (sync): 5 log points, error handler: false, network logging handler: false
22:23:52.239 info host client connected: runtimeHook { address: '127.0.0.1', family: 'IPv4', port: 63624 }
smcenlly commented 2 months ago

Thanks for reporting the problem. This is fixed in Console Ninja v1.0.365+.

rugo83 commented 2 months ago

I’ve updated to v1.0.356. In standard mode of NestJS, console.error works fine, but in monorepo mode, the issue still persists.

To create the monorepo mode: https://docs.nestjs.com/cli/monorepo#monorepo-mode

nest new my-project
cd my-project
nest generate app my-app
npm run start:dev

Additionally, in v1.0.356, Universal Node applications (adding the console-ninja prefix before node app.js) are not working correctly either.

ArtemGovorov commented 2 months ago

Additionally, in v1.0.356, Universal Node applications (adding the console-ninja prefix before node app.js) are not working correctly either.

Thanks reporting the issue. Universal Node applications is fixed in v1.0.357.

smcenlly commented 2 months ago

@rugo83 - thanks for the steps to generate a nestjs mono-repo.

Console Ninja is actually reporting console.error messages, but they are being reported against the wrong file because there's no source map support in nestjs (at least by default) when using mono-repos.

You will see the same source map issue if you were to throw new Error('boom'); in your code - you'll see it reports against /dist/main.js instead of your source file.

Console Ninja requires source maps to report errors (and console.error).

We found a quick way to fix this in our mono-repo, by changing the nest-cli.json file:

{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "apps/my-project/src",
  "compilerOptions": {
    "deleteOutDir": true,
-   "webpack": true,
+   "webpack": false,
    "tsConfigPath": "apps/my-project/tsconfig.app.json"
  },
...

This change will force nest to generate individual files for your source code (the same as when not using a mono-repo); in this mode, source maps are emitted by default, and everything will work for you.

Alternatively, you may investigate how to generate source maps for nestjs webpack mode; this should also fix your problem.

rugo83 commented 2 months ago

Thank you for your help! Both my NestJS and Vite projects are working well with Console Ninja v1.0.357. However, console.error is not showing up in Universal Node applications. Do you have any suggestions on how to resolve this issue in this version? Thanks again!

Vite

image

Universal Node applications

console-ninja node main.js

image

smcenlly commented 2 months ago

Please update to the latest version of Console Ninja, v1.0.358. It should work for you.

rugo83 commented 2 months ago

Thank you for resolving the previous issue. I have encountered a new problem, though. As shown in the screenshot, console.error does not support more than one parameter, and passing a regular object does not display it correctly. Could you please investigate this behavior? I appreciate your help in fixing the earlier problem and look forward to your support on this matter as well.

image

Version

v1.0.359

Universal Node applications

console-ninja node main.js

smcenlly commented 2 months ago

Thanks for reporting your problem. By design, console.error is handled a little differently from other console methods so that Console Ninja captures console.error when it's output by your dependencies, not just your application code. The other console.* methods do not work this way. Unfortunately this behavior means that what we capture is different, and limited.

We've updated Console Ninja to process console.error calls within your application code the same way that it's processing other console.* method calls. In your case, it will fix your problem. In cases where console.error occurs outside of your application code (i.e. occurs in dependencies), then the previous logging behavior will take place.

Please update to Console Ninja v1.0.360 to fix your issue.

rugo83 commented 2 months ago

Thank you! Everything is working fine now after the update.