You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Astro-Sanity集成报错:SSR模块导入失败与配置加载异常

问题分析与解决方案

可能原因1:@sanity/astro版本与Astro v3不兼容

@sanity/astro早期版本对Astro v3的适配存在缺陷,尤其是模块默认导出的处理逻辑,会触发Vite SSR的导入错误。

解决步骤:

  • 查看当前安装的@sanity/astro版本:
    npm list @sanity/astro
    
  • 升级至最新兼容版本:
    npm install @sanity/astro@latest
    
  • 重启开发服务:
    npm run dev
    

可能原因2:导入方式错误(ES模块导出不匹配)

部分版本的@sanity/astro采用命名导出而非默认导出,默认导入会导致解析失败。

解决步骤:

修改astro.config.mjs的导入逻辑为命名导入:

import { sanity } from "@sanity/astro";
import { defineConfig } from "astro/config";

export default defineConfig({
  integrations: [
    sanity({
      projectId: 'vmv3i2a5',
      dataset: 'production',
      apiVersion: '2023-02-08',
      useCdn: false,
    }),
  ],
});

可能原因3:缓存或依赖冲突

Vite缓存、node_modules缓存可能导致模块解析异常。

解决步骤:

  • 删除依赖目录与锁文件:
    rm -rf node_modules package-lock.json
    
  • 重新安装依赖:
    npm install
    
  • 清除Astro与Vite缓存:
    rm -rf .astro dist
    
  • 重启开发服务:
    npm run dev
    

可能原因4:TypeScript类型声明异常

env.d.ts中的类型引用可能存在加载问题,干扰模块解析。

解决步骤:

  • 确保env.d.ts位于项目根目录,无语法错误
  • 暂时注释/// <reference types="@sanity/astro/module" />,重启服务验证是否正常;若恢复正常,再重新添加该声明并检查类型文件是否完整

内容的提问来源于stack exchange,提问作者Laura Conant

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 20:10:06