Skip to content

[Function] Not working with Netlify Dev #1076

@aress31

Description

@aress31

- Do you want to request a feature or report a bug?
I would like to report what I believe to be a bug.

- What is the current behavior?
When developing locally using netlify dev my functions are not detected.

- If the current behavior is a bug, please provide the steps to reproduce.
I have the following functions located in the file functions\create-checkout.js. It is a simple test function to troubleshoot the function.

const express = require('express');
const app = express();
app.get('/ping', function (req, res) {
  res.send('pong');
});
const serverless = require('serverless-http');
module.exports.handler = serverless(app);

This is the content of my netlify.toml configuration file:

# Settings in the [build] context are global and are applied to all contexts
# unless otherwise overridden by more specific contexts.
[build]
    # Directory to change to before starting a build.
    # This is where we will look for package.json/.nvmrc/etc.
    base = "/"
    # Directory that contains the deploy-ready HTML files and assets generated by
    # the build. This is relative to the base directory if one has been set, or the
    # root directory if a base has not been set. This sample publishes the
    # directory located at the absolute path "root/project/build-output"
    publish = "dist/"
    # Directory with the serverless Lambda functions to deploy to AWS.
    functions = "functions"
    # Default build command.
    command = "yarn build"

# If skip_processing = true, all other settings are ignored
[build.processing]
    skip_processing = false
[build.processing.css]
    bundle = true
    minify = true
[build.processing.js]
    bundle = true
    minify = true
[build.processing.html]
    pretty_urls = true
[build.processing.images]
    compress = true

[dev]
    publish = "dist/"
    functions = "functions"

[[headers]]
  # Define which paths this specific [[headers]] block will cover.
  for = "/*"

  [headers.values]
    # Access-Control-Allow-Origin = "https://www.googletagmanager.com"
    X-Frame-Options = "DENY"
    X-XSS-Protection = "1; mode=block"
    # Content-Security-Policy = "frame-ancestors https://www.facebook.com"

    # Multi-value headers are expressed with multi-line strings.
	  # cache-control = '''
	  # max-age=0,
	  # no-cache,
	  # no-store,
	  # must-revalidate'''

[[redirects]]
    from = "/api/*"
    to = ".netlify/functions/:splat"
    status = 200
    force = true # COMMENT: ensure that we always redirect

When browsing to http://localhost:8888/api/ping I am being greeted with the error message Function not found...:
image

- What is the expected behavior?
The expected behaviour is that the express server running in my create-checkout.js function greets me with the message pong when browsing to http://localhost:8888/api/ping or fetching the endpoint with fetch/axios.

- Additional Information
The following shows the output of the command netlify dev:

◈ Netlify Dev ◈
◈ No app server detected and no "command" specified
◈ Running static server from "shop-wc\dist"

◈ Server listening to 3999

◈ Functions server is listening on 55061

   ┌─────────────────────────────────────────────────┐
   │                                                 │
   │   ◈ Server now ready on http://localhost:8888   │
   │                                                 │
   └─────────────────────────────────────────────────┘

◈ Rewrote URL to /.netlify/functions/ping
Request from ::1: GET /.netlify/functions/ping     
Response with status 404 in 1 ms.
Request from ::1: GET /.netlify/functions/ping.html
Response with status 404 in 0 ms.
Request from ::1: GET /.netlify/functions/ping.htm
Response with status 404 in 8 ms.
Request from ::1: GET /.netlify/functions/ping/index.html
Response with status 404 in 1 ms.
Request from ::1: GET /.netlify/functions/ping/index.htm
Response with status 404 in 8 ms.

- Local Environment Information

────────────────────┐
 Environment Info   │
────────────────────┘

  System:
    OS: Windows 10 10.0.19041
    CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
  Binaries:
    Node: 13.12.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.14.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 84.0.4147.105
    Edge: Spartan (44.19041.1.0)

netlify-cli/2.59.0 win32-x64 node-v13.12.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions