Issue with locating RequestHandler in +server.ts file despite various troubleshooting attempts (recreating file, restarting servers, running svelte-check)
+server.ts development code:
import type { RequestHandler } from './$types'
/** @type {import('./$types').PageServerData} */
export const POST = (async ({ clientAddress, request, url }: { clientAddress: string, request: Request, url: string }) => {
console.log(request.body)
try {
const res = await fetch('http://localhost:8787/', {
method: 'POST',
body: request.body
})
if (!!res.ok) {
const data = await res.json()
console.log('data: ', data)
}
} catch(e) {
return new Response(JSON.stringify({ message: 'Error: ', e }), { status: 500 })
}
return new Response(JSON.stringify({ message: 'Success' }), { status: 200 })
}) satisfies RequestHandler
svelte.config.js config:
import adapter from '@sveltejs/adapter-cloudflare';
import { vitePreprocess } from '@sveltejs/kit/vite';
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter(),
}
};
export default config;
vite.config file settings:
import { sveltekit } from '@sveltejs/kit/vite'
import { defineConfig } from 'vitest/config'
export default defineConfig({
plugins: [sveltekit()],
resolve: {
alias: {
$lib: '/src/lib',
$routes: '.svelte-kit/types/src/routes',
}
},
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
}
})
Additonally encountering the error:
Cannot find module '@sveltejs/kit/vite' or its corresponding type declarations.ts(2307)
Persistent issues with new sveltekit installation despite attempted solutions.