1

How do I deploy a server-side rendered Astro site with a Node.js adapter on Netlify?

When i push this site to production I see:

Runtime.ImportModuleError - Error: Cannot find module 'sharp' Require stack: - /var/task/.netlify/functions-internal/entry.js - /var/task/entry.js - /var/runtime/index.mjs

this is probably becouse I showes me in functions tab that i have entry function but i dont specyfy it.

this is my astro.config.mjs

import { defineConfig } from "astro/config";
import preact from "@astrojs/preact";
import sitemap from "@astrojs/sitemap";
import image from "@astrojs/image";
import compress from "astro-compress";

// https://astro.build/config
import node from "@astrojs/node";

// https://astro.build/config
export default defineConfig({
  site: "https://kluzko.tech",
  trailingSlash: "always",
  output: "server",
  adapter: node({
    mode: "standalone",
  }),
  integrations: [
    preact({
      compat: true,
    }),
    sitemap({
      customPages: ["https://kluzko.tech/about", "https://kluzko.tech/contact"],
    }),
    image({
      serviceEntryPoint: "@astrojs/image/sharp",
    }),
    compress({
      css: true,
      html: false,
      img: true,
      js: true,
      svg: false,
      logger: 1,
    }),
  ],
  vite: {
    ssr: {
      noExternal: ["react-hot-toast"],
    },
  },
});

and here is my netlify.toml

[build]
  command = "pnpm build"
  publish = "dist"


IvonaK
  • 119
  • 10

1 Answers1

0

Just install npm i sharp as you've instructed Astro to import it (serviceEntryPoint: "@astrojs/image/sharp").

Here is how you could find it out yourself and learn something new from Astro source code.

Github search in Astro repo for keyword sharp brought me to this piece of code:

import(resolvedOptions.serviceEntryPoint === '@astrojs/image/sharp'
                    ? './loaders/sharp.js'
                    : './loaders/squoosh.js');

Knowing that you've specified '@astrojs/image/sharp' for serviceEntryPoint in your astro.config.mjs, let's open ./loaders/sharp.ts and first line reveals the import that throws an error as sharp package is not installed in your project:

import sharp from 'sharp';

Hope that helps!

Sergey Lukin
  • 471
  • 2
  • 17