#Astro build fails on SSR

19 messages · Page 1 of 1 (latest)

fathom bridge
#

Hello, all. I am not sure why, but on SSR, the build on my Astro project is failing with the following message:

[commonjs--resolver] Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.
error Failed to resolve entry for package "fs". The package may have incorrect main/module/exports specified in its package.json.

My astro.config.mjs file is pretty straightforward:

import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";
import node from "@astrojs/node";
import react from "@astrojs/react";

// https://astro.build/config
export default defineConfig({
output: "server",
integrations: [tailwind(), react()],
adapter: node({
mode: "standalone",
}),
});

If I comment out output: "server", the build runs but obviously doesn't work since I don't have getStaticPaths() set (the intention is to run this as full SSR).

I read that this might be some error in code and so I have failed to create a reproducible example, however I don't know where to look. Already tried to turn off each integration, check if I'm using client: directives on Astro components and some other things.

Any ideas on how I can proceed?

fathom bridge
#

An update on this: I tried creating a brand-new Astro project with the Empty template with pnpm create astro@latest. I then ran pnpm astro add node. It threw an error on me right away. So I'll be moving away from Node as an Astro adapter for now. I'll be sure to update this thread once I get this running.

fathom bridge
#

Last update on this: I tried Deno, and it still hadn't worked for me first time. However, it gave me a more helpful error message: [commonjs--resolver] Cannot bundle Node.js built-in "util" imported from "node_modules/.pnpm/form-data@4.0.0/node_modules/form-data/lib/form_data.js". Consider disabling ssr.noExternal or remove the built-in dependency.

Looking at it first glance, it doesn't seem very helpful at all. However, this dependency is only linked to a single package I was using: Axios. Once I removed Axios and its references, Deno was able to build.

So, for some reason, Astro's SSR mode doesn't like Axios. If anyone knows why, I'd sure like an explanation.

carmine dirge
#

@fathom bridge could you paste your package.json file?

#

I had no problems running with a node adapter.
Which machine/OS are you using? MacOS, Windows etc

#

'fs' sounds like a platform issue

fathom bridge
#

Agreed that it might be a platform issue. Tried to do the same on Stackblitz and it worked no problem.
I'm running Ubuntu 20.04.

#

@carmine dirge Here's my package.json from before I changed adapters, just pretty standard stuff I believe:

"dependencies": {
"@astrojs/node": "^5.1.1",
"@astrojs/react": "^2.1.1",
"@astrojs/tailwind": "^3.1.1",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"astro": "^2.3.0",
"axios": "^1.3.5",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"tailwindcss": "^3.0.24"
},
"devDependencies": {
"@iconify/react": "^4.1.0"
}

carmine dirge
#

I would raise an issue in their github issues. I think Ubuntu might have to do with it

#

Although I would remove some dependencies and retry. One by one.

#

You can also try to make your app run within a docker container to see if that solves the issue.

#

Ah sorry, I think I know what your issue is.

fathom bridge
#

I did not. Dang, I thought I had already read the whole docs.

#

Thanks for all the input. I'll try that and let you know.

#

No cigar. I have this in my astro.config:

output: "server",
adapter: node({
mode: "standalone",
vite: {
ssr: {
noExternal: ["path-to-regexp"],
},
},
}),

#

If this is correct and it still didn't work, I think I'll probably just stick to Deno

carmine dirge
#

its important if node doesnt work on linux ubuntu