@astrojs/node Build Error
Today’s entry is about this very site.
I’m using Astro to build this site, with the Astro Node integration for SSR.
Well, I installed it, and set it up in astro.config.mjs
:
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/[email protected]/node_modules/send/index.js
Stack trace:
at packageEntryFailure (file://.../blog-astro/node_modules/.pnpm/[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:46637:15)
at tryNodeResolve (file://.../blog-astro/node_modules/.pnpm/[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:46450:16)
at Object.handler (file://.../blog-astro/node_modules/.pnpm/[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:65653:15)
at async PluginDriver.hookFirstAndGetPlugin (file://.../blog-astro/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:21099:28)
at async ModuleLoader.resolveId (file://.../blog-astro/node_modules/.pnpm/[email protected]/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
:
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.