gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.14k stars 10.33k forks source link

Serverless function in Gatsby site throwing error and not returning data locally #38913

Open jarren15 opened 3 months ago

jarren15 commented 3 months ago

Preliminary Checks

Description

I've created a serverless function in my Gatsby site as shown in the documentation, but it's throwing an error and not returning the data when accessed locally.

image

Reproduction Link

https://github.com/jarren15/dm_frontend

Steps to Reproduce

  1. Navigate to the serverless function endpoint in the local development environment.
  2. Attempt to fetch data using the serverless function.
  3. Note the error encountered or observe that the fetched data is not returned as expected. ...

Expected Result

When accessing the serverless function locally, it should successfully fetch the data and return it without any errors.

Actual Result

The serverless function is throwing an error and failing to return the fetched data when accessed locally.

Environment

System:
    OS: Windows 11 10.0.22631
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
  Binaries:
    Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (122.0.2365.92)
  npmPackages:
    gatsby: ^5.13.3 => 5.13.3 
    gatsby-plugin-anchor-links: ^1.2.1 => 1.2.1 
    gatsby-plugin-image: ^3.13.1 => 3.13.1 
    gatsby-plugin-manifest: ^5.13.1 => 5.13.1 
    gatsby-plugin-postcss: ^6.13.1 => 6.13.1 
    gatsby-plugin-sanity-image: ^0.13.4 => 0.13.4 
    gatsby-plugin-sass: ^6.13.1 => 6.13.1 
    gatsby-plugin-sharp: ^5.13.1 => 5.13.1 
    gatsby-source-filesystem: ^5.13.1 => 5.13.1 
    gatsby-source-sanity: ^7.9.1 => 7.9.1 
    gatsby-source-wordpress: ^7.13.3 => 7.13.3 
    gatsby-transformer-sharp: ^5.13.1 => 5.13.1 
  npmGlobalPackages:
    gatsby-cli: 5.13.2

Config Flags

No response

7sferry commented 1 month ago

this also happened to me, but only in windows. it worked fine in linux environment. seems like they failed to read windows path to access the function. to fix this upgrade to 5.13.4

Viktor19931 commented 3 weeks ago

You should build functions separetly from project I personally run it locally with netlify

run in macOS