Serverless function endpoint exists but it says it doesn't

Netlify site name: btcvseth.netlify.app

Hello, this is my first time trying to use the serverless functions. I’m using this on a Jekyll site. When I run netlify dev and refresh the build preview it tells me:

ERROR /.netlify/functions/test/' not found.

But when I check my port/endpoint for the function, everything is working with the expected output so I’m not sure what the issue is.

Console output:

hanniabu@New-MacBook btcvseth-info % netlify dev
◈ Netlify Dev ◈
◈ Injected build settings env var: ETHERSCAN
◈ Ignored general context env var: LANG (defined in process)
◈ Loaded function data.
◈ Functions server is listening on 64429
◈ Starting Netlify Dev with custom config
Configuration file: /Users/hanniabu/Documents/github/btcvseth-info/_config.yml
            Source: /Users/hanniabu/Documents/github/btcvseth-info
       Destination: /Users/hanniabu/Documents/github/btcvseth-info/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
       Jekyll Feed: Generating feed for posts
                    done in 0.032 seconds.
 Auto-regeneration: enabled for '/Users/hanniabu/Documents/github/btcvseth-info'
LiveReload address: http://127.0.0.1:35729
    Server address: http://127.0.0.1:4400
  Server running... press ctrl-c to stop.
        LiveReload: Browser connected
      Regenerating: 1 file(s) changed at 2022-02-26 23:16:29
                    netlify.toml
       Jekyll Feed: Generating feed for posts
                    ...done in 0.02107 seconds.

[2022-02-26 23:16:29] ERROR `/.netlify/functions/data' not found.

Browser console log - note that the port it’s accessing isn’t the function port:

GET http://127.0.0.1:4400/.netlify/functions/test/ 404 (Not Found)

Function properly working though:

Function code:

import fetch from 'node-fetch';

exports.handler = async (event, context) => {
  return {
    statusCode: 202,
    body: JSON.stringify({
      data: "hello"
    })
  }
}

Function call:

async function getData() {
  const response = await Promise.all([
    fetch("/.netlify/functions/test/")
  ]);
  console.log(response);
}

netlify.toml:

[build]
	functions = "/_netlify/functions"
	node_bundler = "esbuild"

[dev]
	command = 'bundle exec jekyll serve'
	port = 4400
	publish = '_site/'

Please help. I’ve wasted multiple hours on this and searching for solutions with no luck.

Directory structure:

Are you browsing the site served by CLI or served by your app’s server?

I’m browsing the address for my app’s server, which is server by CLI using the build commands I provided in netlify.toml. This is my netlify dev output:

hanniabu@New-MacBook btcvseth-info % netlify dev
◈ Netlify Dev ◈
◈ Injected build settings env var: ETHERSCAN
◈ Ignored general context env var: LANG (defined in process)
◈ Loaded function data.
◈ Functions server is listening on 64429
◈ Starting Netlify Dev with custom config
Configuration file: /Users/hanniabu/Documents/github/btcvseth-info/_config.yml
            Source: /Users/hanniabu/Documents/github/btcvseth-info
       Destination: /Users/hanniabu/Documents/github/btcvseth-info/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
       Jekyll Feed: Generating feed for posts
                    done in 0.032 seconds.
 Auto-regeneration: enabled for '/Users/hanniabu/Documents/github/btcvseth-info'
LiveReload address: http://127.0.0.1:35729
    Server address: http://127.0.0.1:4400
  Server running... press ctrl-c to stop.
        LiveReload: Browser connected
      Regenerating: 1 file(s) changed at 2022-02-26 23:16:29
                    netlify.toml
       Jekyll Feed: Generating feed for posts
                    ...done in 0.02107 seconds.

[2022-02-26 23:16:29] ERROR `/.netlify/functions/data' not found.

No, what I meant was, Netlify CLI usually starts its own server (typically on port 8888) where the functions are available. You need to make sure, you’re browsing the site on localhost:8888.

Wow that actually worked.

Some feedback:

When reading prior posts and documentation, the language around using /.netlify/functions/function-name and auto-routing to the right port made it sound like this should never be an issue and was the exact reason why they made it like that. Some clarification could definitely be used in some areas around that.

Could you point to a post that says that? Port auto-redirection was never advertised from what I know. If something is unclear in the docs, we can change that.

I’ll need to dig for it, but I actually am still having an issue. The first time restarting the server after removing the port for my app, it loaded on port 8888 and opened the test site automatically:

This was the first time that’s happened and the first time I received that “Server now ready on” message at the bottom there. However, as I started making changes to my page and save it, when it should have refreshed with the updates I instead received this error in the CLI:

error while proxying request: connect ECONNREFUSED ::1:4000

I ended the process and ran netlify dev again, but now every time I run it I’m back to my original issue. I don’t get the Server now ready on http://localhost:8888 message, I don’t get sent there automatically, and nothing shows there when I go there manually.

When it originally worked it was after I deleted port settings for my app so it would use the CLI’s port (8888). It then worked. I didn’t change anything regarding the port or app settings in between it working and not working. The only things I changed were some html and serverless test function.

Are you using Node 17 by any chance?

Yes, I’m using node v17.5.0

Well, then here is the cause:

1 Like