tsed icon indicating copy to clipboard operation
tsed copied to clipboard

Logger layouts are not exported correctly?

Open ThanatosGit opened this issue 2 months ago • 4 comments

When you use the "json" layout as logger as suggested here https://tsed.dev/docs/logger.html#use-json-layout-in-production, you just see the message

Missing json layout doesn't exists.
Have you imported the @tsed/logger/layouts/JsonLayout module in your code?

If you use the suggested import, you just get:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/thanatos/projects/tsed/test-logger/node_modules/@tsed/logger/lib/esm/layouts/components/JsonLayout' imported from /home/thanatos/projects/tsed/test-logger/src/config/logger/index.ts
Did you mean to import "@tsed/logger/lib/esm/layouts/components/JsonLayout.js"?

You have to import it via import "@tsed/logger/layouts/JsonLayout.js" which can be easily added to the documentation and auto generated code from tsed/cli but maybe the layouts should be exported by @tsed/logger instead of referencing some internal paths? Though the components were explicitly omitted from barrelsby by this commit / refactor. https://github.com/tsedio/logger/commit/56f95a1f59490e10ea0029fa827427363c7d6d9c

ThanatosGit avatar Oct 16 '25 12:10 ThanatosGit

You have probably right :) But I don't wan't to embed all layouts in the bundle if isn't necessary to optimize the bundle size.

Romakita avatar Oct 16 '25 13:10 Romakita

@ThanatosGit there is a migration note for logger : https://logger.tsed.dev/introduction/migrate-to-v8.html

This doc explain the correct way to import layouts and appenders from v8. The goals is to reduce the bundle size. Your issue is related to the missing ".js". Add this line to fix your issue:

@tsed/logger/layouts/JsonLayout.js

See you

Romakita avatar Oct 18 '25 09:10 Romakita

@Romakita Yes, I mentioned the correct import in the opening post.

Is this the file which gets copied by the cli? https://github.com/tsedio/tsed/blob/production/tools/integration/src/config/logger/index.ts

The strange thing is that although you create a new project via the CLI, you still have to migrate it, which is somewhat counterintuitive. I see that you changed the docs on the homepage already.

ThanatosGit avatar Oct 18 '25 14:10 ThanatosGit

Arf I forgot the CLI. I’m focused on the next CLI released (which is already fixed), and missed to update the current CLI version.

Romakita avatar Oct 18 '25 17:10 Romakita