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

在Svelte框架中导入组件时遇‘import ... =仅可用于TS文件’错误如何解决?

解决Svelte导入组件时的「'import ... =' can only be used in TypeScript files」错误

在Svelte框架中尝试将组件导入至另一个组件时,若出现以下错误提示:

'import ... =' can only be used in TypeScript files

通常是因为使用了TypeScript专属的导入语法(比如import Modal = require('./Modal.svelte')),而Svelte的JavaScript文件需要采用标准ES模块导入方式。

正确的组件导入代码如下:

import Modal from './Modal.svelte'; // 导入其他组件供使用

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 07:40:24