I’ve built a new vite app out of the box as per the Netlify docs but also have the same problem with a slightly more mature project as well.
Here is /netlify/functions/foo.mts:
import type { Config } from "@netlify/functions";
export const config: Config = {
method: "GET",
path: "/foo",
};
export default async function (): Promise<Response> {
const body = JSON.stringify({ data: "in foo" });
return new Response(body);
}
Here is /netlify/functions/bar.mts :
import type { Config } from "@netlify/functions";
export const config: Config = {
method: "GET",
};
export default async function (): Promise<Response> {
const body = JSON.stringify({ data: "in bar" });
return new Response(body);
}
When I launch npx netlify dev, I get:
❯ npx netlify dev
⬥ Injecting environment variable values for all scopes
⬥ Ignored general context env var: LANG (defined in process)
⬥ Ignored general context env var: LANGUAGE (defined in process)
⬥ Setting up local dev server
⬥ Starting Vite dev server
VITE v7.1.3 ready in 571 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
✔ Vite dev server ready on port 5173
╭─────────────────────── ⬥ ────────────────────────╮
│ │
│ Local dev server ready: http://localhost:8888 │
│ │
╰───────────────────────────────────────────────────╯
⬥ Loaded function foo
⬥ Loaded function bar
(node:42975) [DEP0060] DeprecationWarning: The `util._extend` API is deprecated.
Please use Object.assign() instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
When I travel to http://localhost:8888/.netlify/functions/bar, I get the JSON response and this in the console:
⬥ Loaded function bar
Request from ::1: GET /.netlify/functions/bar
Response with status 200 in 147 ms.
When I travel to http://localhost:8888/.netlify/functions/foo, however, I get an html response of the Vite front page and this appears in the console:
› Warning: Function foo cannot be invoked on /.netlify/functions/foo, because
the function has the following URL paths defined: /bar
If I change the config.path value to /.netlify/functions/foo, I get this perplexing message:
⬥ Reloading function foo...
⬥ Reloaded function foo
› Warning: Function foo cannot be invoked on /.netlify/functions/foo, because
the function has the following URL paths defined: /.netlify/functions/foo
If I comment config.path out, It works like bar.mts does, which is to say, correctly.
⬥ Reloading function foo...
⬥ Reloaded function foo
Request from ::1: GET /.netlify/functions/foo
Response with status 200 in 216 ms.
Thanks!