Joe*_*ger 3 typescript svelte vite sveltekit
我有一个 SvelteKit 项目,由于某种原因,./$types没有 PageLoad 模块(其他项目也有。我不确定我做了/没有做什么才没有它。这是我收到的错误:
Module '"./$types"' has no exported member 'PageLoad'.ts(2305)
Run Code Online (Sandbox Code Playgroud)
这就是我使用它的方式(用于测试):
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params, fetch }) => {
console.log('props from +page.ts: ', params.db_item)
// We fetch the post here using a Worker/Lambda
return params.db_item
}
Run Code Online (Sandbox Code Playgroud)
这是我的 package.json 文件:
{
"name": "test",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"test": "playwright test",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check .",
"format": "prettier --write .",
"surge deploy": "rollup -c; surge public"
},
"devDependencies": {
"@playwright/test": "^1.25.0",
"@sveltejs/adapter-auto": "next",
"@sveltejs/kit": "next",
"node-sass": "^7.0.3",
"prettier": "^2.6.2",
"prettier-plugin-svelte": "^2.7.0",
"svelte": "^3.44.0",
"svelte-check": "^2.7.1",
"svelte-preprocess": "^4.10.6",
"tslib": "^2.3.1",
"typescript": "^4.7.4",
"vite": "^3.1.0"
},
"type": "module",
"dependencies": {
"svelte-share-buttons-component": "^1.5.0"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 svelte.config 文件:
import adapter from '@sveltejs/adapter-cloudflare';
import preprocess from 'svelte-preprocess';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
kit: {
adapter: adapter()
}
};
export default config;
Run Code Online (Sandbox Code Playgroud)
这绝对是疯狂的,但我想通了。
我最初命名了该文件+page.js并将其重命名.ts为. 显然,这让一切都变得糟糕。删除文件并使用 .ts 扩展名创建文件后,$types导入工作正常。文档中没有任何地方提到任何内容,但事实就是如此。
| 归档时间: |
|
| 查看次数: |
3920 次 |
| 最近记录: |