6

I've created an app and a function with Azure CLI, which has a proper structure, so:

/host.json
/local.settings.json
/mycustomfunction/function.json
/mycustomfunction/index.js
/mycustomfunction/package.json
/node_modules

Source code gets downloaded from BitBucket, deployed with Kudu, built (node_modules are fetched, azure is one of them), everything is green.

When it comes to dependencies there is only one - "azure": "^2.0.0-preview"

But when I run the function on Azure, I get error

2017-09-08T13:59:06.091 JavaScript HTTP trigger function processed a request. 2017-09-08T13:59:06.216 Exception while executing function: Functions.mycustomfunction. mscorlib: Error: Cannot find module 'azure' at Function.Module._resolveFilename (module.js:469:15)

The same function works fine locally when run with func host start...

What am I doing wrong? :)

2 Answers 2

4

The root cause should be because you haven't not run the npm install command in the Kudu console of your function app to install the necessary node modules defined in your function app's package.json.

Follow this guide: Node version and Package Management

Below are some highlights from the reference guide above.

After the package.json file is uploaded, run the npm install command in the Kudu remote execution console.

This action downloads the packages indicated in the package.json file and restarts the function app.

After the packages you need are installed, you import them to your function by calling require('packagename'), as in the following example:

// Import the underscore.js library
var _ = require('underscore');
var version = process.version; // version === 'v6.5.0'

module.exports = function(context) {
    // Using our imported underscore.js library
    var matched_names = _
        .where(context.bindings.myInput.names, {first: 'Carla'});
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I've followed this tutorial already and I've run npm install. I also think that npm install is run automatically when you fetch source code from source code repository. But somehow module isnt found yet.
OK, I tried another app with the same dependency (azure) and from what I see npm install has some issues. At least it looks like I get a .staging folder instead of packages inside node_modules folder. I will try to put dependency on specific module that I need vs on azure complete module.
1

It seems that the problem was with the Shared/Consumption model for Azure Functions. I've noticed that when running npm install, most of the time the process would timeout with no packages showing up in the node_modules folder leaving only the .staging folder behind. After creating a new Function App with with dedicated App Service Plan, everything works as expected.

Another (potentially better) solution is to include azure-sb module, instead of azure. It provides enough capabilities to query Azure Service Bus, while it's significantly smaller and Kudu is able to fetch it even with Shared Tier resources.

3 Comments

I was about to try installing individual modules when it worked the second time. Thought that might help with the timeout issue but I must have squeaked under the wire the second time.
Another option would be to try dropping a zipped file of the node_modules using Kudu. Have not tried it so I don't know if that will help.
If you stick the Shared Consumption model, sometimes you have to try a few times. Delete node_modules, npm i, work?, no: repeat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.