Packaging pino throws an error at runtime

When these following conditions happen:

  • using pino for logging
  • type=module in package.json
  • using TS with a target resulting in ESM code

running serverless package will package pino code that uses dynamic require for node:os, resulting in runtime error of packaged code:

Error: Dynamic require of \"node:os\" is not supported

I personally do not believe this is pino issue, but rather something up with packaging. Why? I can use pino just fine if I package everything myself (ie zip -r lambda.zip dist node_modules package.json).

Which brings me to another issue: even when I include custom artifact in serverless.yml (serverless.yml Reference - Serverless Framework - AWS Lambda Guide - Serverless.yml Reference) serverless still does the packaging, ignoring the zip file :man_shrugging:

[EDIT]
Ignore the second issue, I started the custom artifact path with ./. After removing this serverless behaves as expected.

To add even more - when I package stuff using esbuild pino works fine too:

npx esbuild src/io/handlers/**/index.ts --bundle --minify --sourcemap --platform=node --target=es2020 --outdir=dist/io/handlers

So yes, 100% a problem with whatever tool or however serverless packages the codeā€¦