Issue with function in subdirectory

I’ve got a function that’s in the subdirectory (the CLI scaffolded it there) and I’m noticing on build (where I run netlify-lambda build functions that the function in the subdirectory isn’t picked up. Should it be? If not, why does the CLI scaffold it in a subdirectory?

Ok, so apparently this is expected: Does Netlify Lambda support sub-directory ? · Issue #90 · netlify/netlify-lambda · GitHub.

But why does the netlify CLI scaffold into a subdirectory?

Wait - again. :slight_smile: So when I ran netlify dev, my function worked just fine in a subdirectory. So how do I get my production build to work as well?

To be clear, my code is in functions/newsletter-signup/newsletter-signup.js.

When running netlify dev, I can hit it at http://localhost:8888/.netlify/functions/newsletter-signup. Trying the same in production results in a 404 and as I said, in the deploy logs I don’t see it picking up the function. Nor do I see it in the Functions tab.

Sigh - and again - this was my fault. I had a setting in netlify.toml that I did NOT commit to GitHub so it worked locally, but not in production. Dangit Netlify can’t you do what I want and not what I type? :wink:

Hi @cfjedimaster - thanks for being SO GOOD at coming back and resolving your own tickets :smiley: :+1:

Sorry it keeps being tricky. I’m going to leave this thread here as a thought train for anyone who migh find it useful when they debug in the future too :slight_smile:

Hi @cfjedimaster,
Could you share how you got this to work? I’m running into the same issue where netlify cli scaffolds new functions into a subdirectory, but netlify-lambda build doesn’t pick up on them.

Thanks!

It’s been a while, but here is my netlify.toml:

[Settings]
ID = "402b8dc8-41d4-4654-bc81-4495c141b741"

[build]
	functions = "./functions"
	Command = "npm run build"

[dev]
	publish = "."

Thanks! What does your build script look like, then, in package.json?

You can find it here: codabreaker/package.json at master · cfjedimaster/codabreaker · GitHub. But I bet this is what you need:

  "scripts": {
    "prebuild": "cd functions/get-all && npm i",
    "build": "node build.js"
  },

Although - this doesn’t mention the newsletter-signup thing at all. Feel free to poke around the repo more, it’s for a small site.

1 Like