#Using nodes builtins

4 messages · Page 1 of 1 (latest)

prime holly
#

import inspect from 'node:util';
raises error 'cannot find module' while documentation says builtins can be used is Astro files

formal steppeBOT
#

Hi @prime holly. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

You’re right that the docs say Node built-ins are supported, but there are some important caveats.

The docs specify:

Astro supports Node.js built-ins, with some limitations, using Node’s newer node: prefix. There may be differences between development and production, and some features may be incompatible with on-demand rendering. Some adapters may also be incompatible with these built-ins modules or require configuration… [Node builtins]

So:

import util from 'node:util';

is the documented pattern, and the example uses util.MIMEType. [Node builtins]

If import inspect from 'node:util' is giving “cannot find module”:

  1. The knowledge sources do not explain this specific error for node:util or inspect, only that:

    • Support is partial and adapter-dependent.
    • Some environments (e.g. Cloudflare, Azion) require extra configuration or may not support certain Node APIs at all. [Cloudflare Node.js; Azion troubleshooting]
  2. The docs do not provide a troubleshooting section for “cannot find module 'node:util'” specifically, so I can’t say exactly why it fails in your setup from the provided sources.

From the docs alone, the only concrete guidance is:

  • Use the node: prefix (which you are).
  • Be aware that support depends on your adapter / runtime and may require extra configuration (e.g. vite.ssr.external for Cloudflare). [Cloudflare Node.js]
#

Given the limitations of the knowledge sources, I can’t provide a definitive fix for your exact error, only confirm that:

  • Your usage matches the documented pattern.
  • The error is likely due to environment/adapter limitations or configuration, which the docs mention in general but do not detail for node:util specifically.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: