Function not found error when using netlify dev with sveltekit

Hi, I’m trying to use the Netlify image CDN to deliver images to my sveltekit site. I’m trying to test it using the netlify dev command to test it locally.

When I run netlify dev i get the following console output:


◈ Netlify Dev ◈
◈ Injecting environment variable values for all scopes
◈ Ignored general context env var: LANG (defined in process)
◈ Ignored site settings env var: MAPBOX_API_ACCESS_TOKEN (defined in .env file)
◈ Injected .env file env var: MAPBOX_API_ACCESS_TOKEN
◈ Injected site settings env var: NETLIFY_AUTH_TOKEN
◈ Injected netlify.toml file env var: NODE_ENV
◈ Injected netlify.toml file env var: targetport
◈ Injected netlify.toml file env var: port
◈ Injected netlify.toml file env var: command
◈ Injected netlify.toml file env var: framework
◈ Injected .env file env var: BASE_URL
◈ Setting up local development server
Cleaned up .netlify\functions-internal.
◈ Starting Netlify Dev with SvelteKit

> 19mil-site-2024@0.0.1 dev
> vite dev


  VITE v5.0.12  ready in 1592 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
✔ Waiting for framework port 5173. This can be configured using the 'targetPort' property in the netlify.toml

   ┌─────────────────────────────────────────────────┐
   │                                                 │
   │   ◈ Server now ready on http://localhost:8888   │
   │                                                 │
   └─────────────────────────────────────────────────┘

◈ Rewrote URL to /.netlify/functions/sveltekit-render.js
Request from ::ffff:127.0.0.1: GET /.netlify/functions/sveltekit-render.js
Response with status 404 in 2 ms.

And when I visit localhost:8888 i get a 404 response saying 'funtion not found . . . ’

This is the Dev Context in my netlify.toml:

# Dev context: environment variables set here
# are available for local development environments
# run using Netlify Dev. These values can be
# overwritten on branches that have a more specific
# branch context configured.
[context.dev.environment]
  NODE_ENV = "development"
  targetport = 5173
  port = 8888
  command = "npm run dev"
  framework = "custom"

I’m not trying to use any edge functions. My .netlify/ directory has the following structure:

.netlify/
- blobs-serve/
-functions-internal/
-plugins/
-server/
-servless.js
-shims.js
-state.json

Let me know if any other information is required to help fix.

Thanks in advance.

You seem to have configured some Netlify Redirects somewhere in your project. Removing those should fix this.

Hi Hrishikesh, I haven’t done that directly, it must have been done automatically by netlify. I don’t have a /functions directory nor a file called sveltekit-render.js. I’ve searched my project for both of those and have returned no results. Do you know how I can remove the redirects?

SvelteKit’s Netlify adapter adds that redirect and also generates the function. Check your publish directory or simply clone your project fresh in a new folder to see if you still reproduce this.