在本地可以工作但在Vercel上不行的astrojs/image问题的解决方法是在Vercel配置中指定image模块的路径。 代码示例:
import {astro} from "@astrojs/renderer";
import image from "@astrojs/image";
astro.config({
runtime: "react",
paths: {
"@astrojs/image": "/_astro/src/node_modules/@astrojs/image/dist/image.cjs.js",
},
bundler: {
// configure the Astro 11+ bundler
sourceMaps: true,
runtime: "automatic-splitting",
},
});
astro.use(image());
在Vercel上仍然无法正常工作时,还可以在代码中通过log()
来定位问题所在。
import {astro} from "@astrojs/renderer";
import image from "@astrojs/image";
astro.config({
runtime: "react",
paths: {
"@astrojs/image": "/_astro/src/node_modules/@astrojs/image/dist/image.cjs.js",
},
bundler: {
// configure the Astro 11+ bundler
sourceMaps: true,
runtime: "automatic-splitting",
},
});
astro.use(image().log());