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

SvelteKit+TypeScript项目报错:未知编译选项'preserveValueImports'

解决SvelteKit+TypeScript项目中preserveValueImports编译错误

核心原因

preserveValueImports是TypeScript 5.0及以上版本才新增的编译选项,你当前使用的4.9.4/4.8.4版本不支持这个配置,所以会触发报错。

具体解决步骤

  • 先卸载全局安装的TypeScript,避免全局版本干扰项目本地依赖:
    npm uninstall -g typescript
    # 用pnpm的话执行这个
    pnpm uninstall -g typescript
    
  • 进入项目目录,安装TypeScript 5.x版本到项目本地:
    npm install typescript@^5.0.0 --save-dev
    # pnpm的话执行这个
    pnpm add typescript@^5.0.0 -D
    
  • 保留tsconfig.json里的preserveValueImports选项,不需要删除,TS5.x版本已经支持该配置。
  • 重启代码编辑器,让编辑器加载项目本地的TS版本,而非全局旧版本。

额外排查点

如果重启后仍报错,以VS Code为例:按Ctrl+Shift+P(Windows)/Cmd+Shift+P(Mac),输入TypeScript: Select TypeScript Version,选择Use Workspace Version(即项目本地安装的5.x版本)。

内容的提问来源于stack exchange,提问作者J Creations

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 08:30:52