javascript 如何在Netlify上使用Node.js适配器部署ssr Astro站点?

zf9nrax1  于 2023-04-19  发布在  Java
关注(0)|答案(1)|浏览(124)

如何在Netlify上使用Node.js适配器部署服务器端渲染的Astro站点?
当我把这个网站推向生产时,我看到:
Runtime.ImportModuleError -错误:找不到模块“footer”需要堆栈:-/var/task/.netlify/functions-internal/entry.js -/var/task/entry.js- /var/runtime/index.mjs
这可能是因为我在函数选项卡中显示了我有入口函数,但我没有指定它。
这是我的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"],
    },
  },
});

这是我的netlify.toml

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

rekjcdws1#

只需安装npm i sharp,就像您指示Astro导入它一样(serviceEntryPoint: "@astrojs/image/sharp")。
以下是您如何自己找到它并从Astro源代码中学习新东西的方法。
Github search in Astro repo for keyword sharp让我看到了这段代码:

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

知道你已经在astro.config.mjs中为serviceEntryPoint指定了'@astrojs/image/sharp',让我们打开./loaders/sharp.ts,第一行显示导入抛出错误,因为你的项目中没有安装sharp包:

import sharp from 'sharp';

希望有帮助!

相关问题