# Netlify dev: function returns 404 when using functions/functionname/index.js syntax instead of functions/functionname.js

**URL:** <https://answers.netlify.com/t/netlify-dev-function-returns-404-when-using-functions-functionname-index-js-syntax-instead-of-functions-functionname-js/24124>\
**Category:** Support\
**Tags:** netlify-cli\
**Created:** [October 9, 2020, 3:01pm UTC](https://answers.netlify.com/t/netlify-dev-function-returns-404-when-using-functions-functionname-index-js-syntax-instead-of-functions-functionname-js/24124 "2020-10-09T15:01:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ardiewen](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/ardiewen/32/6163_2.png) [@ardiewen](https://answers.netlify.com/u/ardiewen)\
**Post date:** [October 9, 2020, 3:01pm UTC](https://answers.netlify.com/t/netlify-dev-function-returns-404-when-using-functions-functionname-index-js-syntax-instead-of-functions-functionname-js/24124/1 "2020-10-09T15:01:51Z")

</div>

Hi there, I’m experiencing the following issue:

According to this [documentation](https://docs.netlify.com/functions/build-with-javascript/), we should be able to use an index.js file inside of a folder name to reach the endpoint.

E.g. `/functions/hello-world.js` should be equivalent to `/functions/hello-world/index.js`

This works fine in production (I’m using a custom build process via Gatsby Cloud, the `onPostBuild` hook and `@netlify/zip-it-and-ship-it`).

**Examples:**  
[https://gatsby-cloud-netlify-functions.netlify.app/.netlify/functions/test](https://gatsby-cloud-netlify-functions.netlify.app/.netlify/functions/test)  
[https://gatsby-cloud-netlify-functions.netlify.app/.netlify/functions/hello-world](https://gatsby-cloud-netlify-functions.netlify.app/.netlify/functions/hello-world)

However, this does _ **not work** _ when utilizing `netlify dev` during local development with a corresponding `netlify.toml` file. When I attempt to hit the functions on localhost, I receive the following console errors:

GET [http://localhost:8888/.netlify/functions/hello-world](http://localhost:8888/.netlify/functions/hello-world)

```auto
Request from ::ffff:127.0.0.1: GET /.netlify/functions/hello-world
Response with status 200 in 9 ms.

```

GET [http://localhost:8888/.netlify/functions/test](http://localhost:8888/.netlify/functions/test)

```auto
Request from ::ffff:127.0.0.1: GET /.netlify/functions/test
Response with status 404 in 0 ms.
Request from ::ffff:127.0.0.1: GET /.netlify/functions/test.html
Response with status 404 in 0 ms.
Request from ::ffff:127.0.0.1: GET /.netlify/functions/test.htm
Response with status 404 in 0 ms.
Request from ::ffff:127.0.0.1: GET /.netlify/functions/test/index.html
Response with status 404 in 0 ms.
Request from ::ffff:127.0.0.1: GET /.netlify/functions/test/index.htm
Response with status 404 in 0 ms.

```

Here’s my minimal repo configuration:

**Base Repo:** `gatsby-starter-default`

**Folder Hierarchy** :

```auto
.
|-- src
| |-- functions
| | |-- hello-world.js
| | |-- test
| | | |-- index.js

```

**netlify.toml:**

```auto
[build]
  functions="public/functions" #this is for gatsby cloud config

[dev]
  functions="src/functions"

```

Running gatsby with `netlify dev` and what should be all the appropriate ports.

Any advice would be appreciated.

---

<div class="post-metadata">

**Author:** ![jen](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/jen/32/6044_2.png) [@jen](https://answers.netlify.com/u/jen)\
**Post date:** [October 16, 2020, 5:59pm UTC](https://answers.netlify.com/t/netlify-dev-function-returns-404-when-using-functions-functionname-index-js-syntax-instead-of-functions-functionname-js/24124/2 "2020-10-16T17:59:52Z")

</div>

Hey @ardiewen,  
I responded and tagged you but realized I misspoke! I can confirm that this is the CLI behavior. When you use the functionName/index.js format, the CLI doesn’t find index.js given the functions directory that you set in the [dev] block.

Would you be willing to open a feature request on the CLI repo for parity with the Netlify platform on this? I know the CLI team would also love a PR if you were interested. I think you’d be working in here: [cli/get-functions.js at 294818b430cd0e2a93e648b533cd83d0352853cf · netlify/cli · GitHub](https://github.com/netlify/cli/blob/294818b430cd0e2a93e648b533cd83d0352853cf/src/utils/get-functions.js)

You can see the whole flow by checking out `cli/src/commands/functions/invoke.js`. If you try `netlify functions invoke:test` in your example above, you’ll get this error:

> <https://github.com/netlify/cli/blob/294818b430cd0e2a93e648b533cd83d0352853cf/src/commands/functions/invoke.js#L191-L193>

because the `isValidFn` check fails. That fails because `getFunctions` fails:

> <https://github.com/netlify/cli/blob/294818b430cd0e2a93e648b533cd83d0352853cf/src/commands/functions/invoke.js#L45>

It sounds like you have a workaround, but please let us know if there’s anything else we can help with.

---

<div class="post-metadata">

**Author:** ![ardiewen](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/ardiewen/32/6163_2.png) [@ardiewen](https://answers.netlify.com/u/ardiewen)\
**Post date:** [October 27, 2020, 2:15pm UTC](https://answers.netlify.com/t/netlify-dev-function-returns-404-when-using-functions-functionname-index-js-syntax-instead-of-functions-functionname-js/24124/3 "2020-10-27T14:15:41Z")

</div>

Thanks @jen for looking into this.

I submitted a PR per your suggestion:

> <https://github.com/netlify/cli/pull/1476>
>
> \*\*- Summary\*\*
> 
> Per the \[Build with Javascript documentation\](https://docs.netl…ify.com/functions/build-with-javascript/), functions ought to support the following naming formats:
> 
> \- my\_functions/functionname.js
> \- my\_functions/functionname/functionname.js
> \- my\_functions/functionname/index.js
> 
> Currently, this works perfectly fine on Netlify hosted production environments, but fails when running \`netlify dev\` via the CLI.
> 
> For more details on how to replicate this problem, including a minimal reproduction, please see this \[support thread\](https://community.netlify.com/t/netlify-dev-function-returns-404-when-using-functions-functionname-index-js-syntax-instead-of-functions-functionname-js/24124/2) I created on the Community Forums.
> 
> \*\*- Test plan\*\*
> 
> 1. I first tested some basic scenarios in a production environment hosted on Netlify to understand the expected behaviour when different naming conventions (and different combinations) are used, for example:
> 
> \`\`\`
> .
> |-- my\_functions
> | | |-- bob
> | | | |-- bob.js
> | | | |-- index.js
> | | |-- test
> | | | |-- test.js
> | | |-- test2
> | | | |-- index.js
> | | |-- test3
> | | | |-- index.js
> | | | |-- test3.js
> | | |-- hello-world.js
> \`\`\`
> 
> This can be verified here: https://gatsby-cloud-netlify-functions.netlify.app/
> e.g. https://gatsby-cloud-netlify-functions.netlify.app/.netlify/functions/hello-world.js etc...
> 
> 2. In the above scenarios, everything works as expected with the ambiguous cases being \`bob\` and \`test3\` where both \`functionname/index.js\` and \`functionname/functionname.js\` files exist. In these cases, the production environment takes the the named function file, if it exists, then the index file, if it exists AND the named function file doesn't exist.
> 
> This behaviour can be confirmed here:
> Uses bob.js: https://gatsby-cloud-netlify-functions.netlify.app/.netlify/functions/bob
> Uses test3.js: https://gatsby-cloud-netlify-functions.netlify.app/.netlify/functions/test3
> 
> 
> 3. This PR reflects this behaviour in the local \`netlify dev\` environment.
> 
> 4. Per \[this conversation\](https://github.com/netlify/cli/issues/694#issuecomment-716717020), there is a failing test for \`should deploy edge handlers when directory exists\` but all other tests appear to be passing fine (as far as I can see).
> 
> \*\*- Description for the changelog\*\*
> 
> Adds missing support for naming functions using the \`my\_functions/functionname/index.js\` convention per official documentation.
> 
> \*\*- A picture of a cute animal (not mandatory but encouraged)\*\*
> 
> dog tax:
> !\[IMG\_0786\](https://user-images.githubusercontent.com/39966887/97306832-5d257000-1835-11eb-9246-13dea136c0bb.JPG)

---

<div class="post-metadata">

**Author:** ![jen](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/jen/32/6044_2.png) [@jen](https://answers.netlify.com/u/jen)\
**Post date:** [October 27, 2020, 5:07pm UTC](https://answers.netlify.com/t/netlify-dev-function-returns-404-when-using-functions-functionname-index-js-syntax-instead-of-functions-functionname-js/24124/4 "2020-10-27T17:07:46Z")

</div>

Amazing!!! Thanks so much for your contribution here 🏆
