--- title: "@astrojs/node Build Error" tags: ["astro"] category: "Astro" description: "Always prefix native imports with `node:`, even in dependencies. If a dependency doesn't do it, adjust your build-step to do it for you." date: 2024-11-23 --- Today's entry is about this very site. I'm using [Astro](https://astro.build) to build this site, with the [Astro Node](https://github.com/withastro/astro/tree/main/packages/integrations/node) integration for SSR. Well, I installed it, and set it up in `astro.config.mjs`: ```js import { defineConfig } from "astro/config"; import node from "@astrojs/node"; export default defineConfig({ // pre-render by default; opt-in to dynamic SSR: output: "hybrid", adapter: node({ mode: "standalone", }), }); ``` It ran fine in dev mode (`pnpm run dev`), but when I tried to build it (`pnpm run build`), I got this error: ``` 23:29:44 [ERROR] [vite] x Build failed in 331ms [commonjs--resolver] Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json. file: .../blog-astro/node_modules/.pnpm/send@0.19.1/node_modules/send/index.js Stack trace: at packageEntryFailure (file://.../blog-astro/node_modules/.pnpm/vite@5.4.11_sass@1.81.0/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:46637:15) at tryNodeResolve (file://.../blog-astro/node_modules/.pnpm/vite@5.4.11_sass@1.81.0/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:46450:16) at Object.handler (file://.../blog-astro/node_modules/.pnpm/vite@5.4.11_sass@1.81.0/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:65653:15) at async PluginDriver.hookFirstAndGetPlugin (file://.../blog-astro/node_modules/.pnpm/rollup@4.27.2/node_modules/rollup/dist/es/shared/node-entry.js:21099:28) at async ModuleLoader.resolveId (file://.../blog-astro/node_modules/.pnpm/rollup@4.27.2/node_modules/rollup/dist/es/shared/node-entry.js:20132:15)  ELIFECYCLE  Command failed with exit code 1. ``` Of course I searched the 'net, and never found the exact same issue; only similar issues. This is surprising, because it's not like I have an edge-case setup. Anyway, long story short, the fix was not to be found on the Internet, but on a hunch I added the following to `astro.config.mjs`: ```js import { defineConfig } from "astro/config"; import node from "@astrojs/node"; export default defineConfig({ // pre-render by default; opt-in to dynamic SSR: output: "hybrid", adapter: node({ mode: "standalone", }), vite: { resolve: { alias: { fs: "node:fs", }, }, }, }); ``` This worked famously.