【问题标题】:SvelteKit PageLoad module not found找不到 SvelteKit PageLoad 模块
【发布时间】:2023-01-11 05:20:24
【问题描述】:

我有一个 SvelteKit 项目,出于某种原因,./$types 没有模块 PageLoad(其他项目有。我不确定我做了什么/没有做什么没有它。这是我的错误我得到:

Module '"./$types"' has no exported member 'PageLoad'.ts(2305)

这就是我使用它的方式(用于测试):

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
}

这是我的 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"
    }
}

这是我的 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;

【问题讨论】:

标签: typescript svelte vite sveltekit


【解决方案1】:

这绝对是疯狂的,但我想通了。

我最初将文件命名为+page.js 并且更名它到.ts。显然,这会把一切都搞砸。删除文件后和创造它带有 .ts 扩展名,$types 导入工作完美。它在文档中没有任何说明,但事实就是如此。

【讨论】:

  • 你应该把这件事告诉 sveltekit 团队。感谢您的发现。
猜你喜欢
  • 2021-11-05
  • 2022-11-17
  • 2022-11-16
  • 2022-11-02
  • 2022-12-15
  • 2022-01-17
  • 2018-02-21
  • 2021-07-23
相关资源
最近更新 更多