Sveltekit -无法导入任何以$app或$env开头的文件



我不能使用任何导入,包括$app或$env或任何路径相关的变量在文件中创建的"外部"SvelteKit。

的例子:

socketio/server.ts

import * as FriendsService from '../src/lib/services/friends';

/服务/friends.ts

import { JWT_ACCESS_TOKEN_SECRET } from "$env/static/private";

错误:

TSError:无法编译TypeScript:. ./src/lib/服务/朋友。ts:2:41 -错误TS2307:找不到模块'$env/static/private'或其相应的类型声明。

这里有关于这个bug的更多信息:

https://github.com/sveltejs/kit/issues/1485

我想知道是否有人找到了解决这个问题的方法。

编辑:

我假设有一种方法可以做到这一点,我用ts-node命令运行服务器,但我应该让Vite以某种方式看到它?

我通过在tsconfig.json中添加"extends": "./.svelte-kit/tsconfig.json"来修复它:

// tsconfig.json
{
"compilerOptions": {
...
},
"extends": "./.svelte-kit/tsconfig.json"
}

最新更新