Azure Functions - Import Custom Node Module

2020-07-19 21:02发布

问题:

I'm experimenting with Azure Functions. I'm trying to use a third-party Node module in my function. However, I've been unable to figure out how to import it.

{
  "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "requestId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "statusCode": 500,
  "errorCode": 0,
  "messsage": "Exception while executing function: Functions.analyze -> Error: Cannot find module 'moment'\n    at Function.Module._resolveFilename .."
}

I'm just trying to import the moment.js Node library. I was unable to find any documentation around this scenario though.

Does anyone know how to import a third-party module into Azure Functions?

回答1:

  1. In your function app in the Azure portal, click Platform features and Advanced tools (Kudu).

  1. cd into your function directory via Debug console (CMD or PowerShell) and run the command: npm install moment.