Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serverless function demo not working locally as described #11

Open
skberko opened this issue Aug 22, 2022 · 3 comments
Open

Serverless function demo not working locally as described #11

skberko opened this issue Aug 22, 2022 · 3 comments

Comments

@skberko
Copy link

skberko commented Aug 22, 2022

TL;DR

Serverless functions may not run in netlify dev mode without additional setup not currently specified in the feature tour docs.

Details

👋 Howdy, Netlify friends!

I just went through this repo in preparation for a chat with the Netlify dev team tomorrow and got a bit stuck with the Create Your First Serverless Function section of the demo. Specifically, I was able to deploy and get a serverless function running in production but not locally (i.e. using netlify dev on my machine).

Unless I'm missing something (definitely possible, given my rusty JS chops!), it seems like these instructions on the Netlify Functions page may need a bit of tweaking:

Save it, then run netlify dev to test locally.
Check your work by clicking the button below!

When I create the function and run netlify dev on my machine as instructed, then click Test Your Function, I get the following error:

image

In the local server logs, I'm seeing:

◈ Starting Netlify Dev with Astro

> @example/[email protected] dev
> astro dev

[19:29:41] [snowpack] Hint: run "snowpack init" to create a project config file. Using defaults...
[19:29:41] [snowpack] Ready!
[19:29:41] [snowpack] watching for file changes... 
[dev server] Server started in 383ms.
[dev server] Local: http://localhost:3000/
[access] /.netlify/functions/hello-world
[access] /404
[access] Not Found: /.netlify/functions/hello-world
⠼ Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml

curl-ing the function endpoint directly doesn't seem to be working either:

$ curl localhost:3000/.netlify/functions/hello-world
Not Found%    

I played around with different filenames and paths for a bit before deciding to deploy to production to see if I could break my site there. However, to my surprise, the exact same code worked in prod:

image

Unlike in dev, in production, curl-ing the function endpoint works as expected:

$ curl https://MY-SUBDOMAIN.netlify.app/.netlify/functions/hello-world
hello world!%

In case it helps, here's a screenshot of the function I wrote (simple copy-pasta from the instructions) as well as its location within my project:

image

I'm guessing that there must be some additional setup needed to spark the /.netlify path magic and get functions running locally. It could be great if you could update the repo to include instructions on how to do that - or at least remove the suggestion to try running functions locally so anxious candidates like me don't tear more hair out than necessary 😅

@klavavej
Copy link

Thanks for reporting this issue @skberko !

Based on the local server logs you shared, I suspect you may be encountering a known Netlify CLI bug that manifests with only certain node.js versions. Could you please run node -v and let me know what version of node.js you're using? If you're using v17+, please try downgrading to v16 and that should hopefully resolve the problem.

Related CLI issues:

@skberko
Copy link
Author

skberko commented Aug 23, 2022

Thanks for the reply, @klavavej. I was originally on node 18.7.0. Just downgraded to 16.17.0, and serveless functions are now working:

[access] /
[access] /deploy-previews
[access] /functions
Request from ::ffff:127.0.0.1: GET /.netlify/functions/hello-world
Response with status 200 in 54 ms.

Not sure this is related to #3617, as the server started fine on both versions for me. Some of those other issues look relevant, though.

Anyhow, hope this helps! 🙂

@Mario8419
Copy link

Any updates on the Node 17 / 18 versions, related to the digital envelope routines::unsupported bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants