I'm currently switching from CommonJS modules to ES modules and encountering some issues with my Fastify-Cli project.
I'm using a custom logging module which I'm setting when running the command
fastify start -P -L ./utils/multi-stream-logger.js -o app.js
Problem is it doesn't work anymore as a ES module, error is:
Error [ERR_REQUIRE_ESM]: require() of ES Module multi-stream-logger.js from fastify-cli/util.js not supported.
Instead change the require of multi-stream-logger.js in fastify-cli/util.js to a dynamic import() which is available in all CommonJS modules.
at requireModule (fastify-cli/util.js:29:12)
at runFastify (fastify-cli/start.js:98:16) {
code: 'ERR_REQUIRE_ESM'
As the require is inside the fastify-cli lib (fastify-cli/util.js) I can't change the require of the module. How can I solve this so this works with an ES module?
I've encountered the same problem today, loading aditional logger configuration file seems not supported in ES module projects(with type: "module" in nearest package.json) yet.
Here is how I fixed the logger customizing issue, instead of specifying an external logger configuration file, we could set FastifyServerOptions in our app.js/app.ts file.
app.ts (in my ts project)
or app.js
fastify start -o -P app.jsWish this could help you with your logger issue.