# Packaging pino throws an error at runtime

**URL:** <https://forum.serverless.com/t/packaging-pino-throws-an-error-at-runtime/20923>\
**Category:** Serverless Framework\
**Created:** [January 22, 2025, 1:12am UTC](https://forum.serverless.com/t/packaging-pino-throws-an-error-at-runtime/20923 "2025-01-22T01:12:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![codan84](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/codan84/32/5837_2.png) [@codan84](https://forum.serverless.com/u/codan84)\
**Post date:** [January 22, 2025, 1:12am UTC](https://forum.serverless.com/t/packaging-pino-throws-an-error-at-runtime/20923/1 "2025-01-22T01:12:01Z")

</div>

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:

```auto
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](https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml#package)) serverless still does the packaging, ignoring the zip file 🤷‍♂️

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

---

<div class="post-metadata">

**Author:** ![codan84](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/codan84/32/5837_2.png) [@codan84](https://forum.serverless.com/u/codan84)\
**Post date:** [January 22, 2025, 2:49am UTC](https://forum.serverless.com/t/packaging-pino-throws-an-error-at-runtime/20923/2 "2025-01-22T02:49:30Z")

</div>

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

```auto
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…

---

<div class="post-metadata">

**Author:** ![jtryearlybird](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@jtryearlybird](https://forum.serverless.com/u/jtryearlybird)\
**Post date:** [February 27, 2025, 7:31am UTC](https://forum.serverless.com/t/packaging-pino-throws-an-error-at-runtime/20923/3 "2025-02-27T07:31:19Z")

</div>

were you able to find a solution? i am running into this exact error now (node:os dynamic)

---

<div class="post-metadata">

**Author:** ![dividebyzero](https://avatars.discourse-cdn.com/v4/letter/d/f14d63/32.png) [@dividebyzero](https://forum.serverless.com/u/dividebyzero)\
**Post date:** [March 12, 2025, 10:51pm UTC](https://forum.serverless.com/t/packaging-pino-throws-an-error-at-runtime/20923/4 "2025-03-12T22:51:31Z")

</div>

I was experiencing the same problem and I ended up having to remove “type”: “module” from my package.json. It’s not ideal but it seems like when paired with serverless some packages do not mesh well with ESM standards. In my case I had multiple packages I was using that were using dynamic imports so it wasn’t something I could change myself. Once I removed this line I could build and deploy with serverless.
