如何在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"
1条答案
按热度按时间rekjcdws1#
只需安装
npm i sharp
,就像您指示Astro导入它一样(serviceEntryPoint: "@astrojs/image/sharp"
)。以下是您如何自己找到它并从Astro源代码中学习新东西的方法。
Github search in Astro repo for keyword
sharp
让我看到了这段代码:知道你已经在
astro.config.mjs
中为serviceEntryPoint
指定了'@astrojs/image/sharp',让我们打开./loaders/sharp.ts,第一行显示导入抛出错误,因为你的项目中没有安装sharp
包:希望有帮助!