Unable to successfully run `functions:invoke`


I’ve been banging my head against a wall trying to get functions:invoke to properly work. I’ve taken a look at similar posts like this one, as well as GitHub issues that have been merged into the netlify-cli codebase like this one, but I haven’t solved my issue.

I’ve tried a series of netlify.toml files, but the original I started with (and the one I would like to ideally have) is the following:


  publish = "public"
  functions = "functions-build"


package = "netlify-plugin-gatsby-cache"

I have Netlify Dev running in one Bash shell. In my other Bash shell, I run netlify functions:invoke my-function and receive the following error and stack trace:

TypeError: Cannot read property 'dir' of undefined
    at module.exports.serverSettings (C:/Users/shand/AppData/Roaming/npm/node_modules/netlify-cli/src/utils/detect-server.js:75:13)
    at FunctionsInvokeCommand.run (C:/Users/shand/AppData/Roaming/npm/node_modules/netlify-cli/src/commands/functions/invoke.js:44:26)        
    at FunctionsInvokeCommand._run (C:/Users/shand/AppData/Roaming/npm/node_modules/netlify-cli/node_modules/@oclif/command/lib/command.js:44:31)
    at async Config.runCommand (C:/Users/shand/AppData/Roaming/npm/node_modules/netlify-cli/node_modules/@oclif/config/lib/config.js:172:9)   
    at async Main.run (C:/Users/shand/AppData/Roaming/npm/node_modules/netlify-cli/node_modules/@oclif/command/lib/main.js:21:9)
    at async Main._run (C:/Users/shand/AppData/Roaming/npm/node_modules/netlify-cli/node_modules/@oclif/command/lib/command.js:44:20)

I’ve taken a look at detect-server.js and see that the flags object is undefined, which causes the error. Does anyone have any insights on how to get past this to get my function invocations working?

I have tried using netlify-cli v2.53.0, v2.48.0, and v2.46.0, all with the same results

Hi @shandysulen, it looks like you ran into a bug. Good news is that it looks like it’s already fixed: https://github.com/netlify/cli/pull/878. And the latest release (v2.54.0) should include the fix. Can you give that a try?

Thanks for the tip! It works just as expected now :sunglasses: