Netlify serverless function works in dev mode but not working after deployed

Hi guys, I was trying to learn how to use serverless functions. It is working in “netlify dev”, but no matter what I tried the serverless function is not found when deployed.

This is the link to my demo website: https://test-serverless-function-aaassww.netlify.app/. The website is built with Qwik framework with the initial setup.

This is how I write the function in netlify/functions/hello-world.mjs:

export default async () => {
  return new Response(‘<p>Hello world</p>’, {
    status: 200,
    headers: { ‘Content-Type’: ‘text/html’ }
  })
}

export const config = {
  path: “/hello-world”,
}

In the “netlify dev” mode when I go to “http://localhost:8888/hello-world”, it is working.

After the website is built and deploy, I can find the function on the dashboard

But when I try to access the function on production, “https://test-serverless-function-aaassww.netlify.app/hello-world”, I was getting 404 error, stating resource not found.

I also tried “https://test-serverless-function-aaassww.netlify.app/.netlify/functions/hello-world”, but it was not working too.

I have created a Github repo for this: https://github.com/HaoZhenSiow/test-serverless-function

Please help a bro out, thanks in advance.

Qwik runs on Edge Functions, which run before Netlify Functions. Thus, the framework captures all of your requests and doesn’t allow Netlify Functions to run. Refer to: Allow excluding paths when using Netlify Edge Functions · Issue #10584 · sveltejs/kit · GitHub (valid for Qwik as well). You can use the workaround mentioned there, but you’d have to change the name of the Edge Function to the one built by Qwik.

Hi, thanks for the reply. I manage to make it work. The extension have to be .ts or .js or maybe .mjs, I was using .tsx/.jsx. Not sure if there is other things but for now it is working.

Yes the application run on Deno, but you can create Netlify Functions which run on Node and send request to the Netlify Function endpoint.