1

I have a node.js app which uses express and runs locally with no problems. However, on Azure I am seeing:

Application has thrown an uncaught exception and is terminated:
Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\home\site\wwwroot\server.js:1:79)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

The packages.json file contains the dependency:

"express": "^4.15.3"

Assuming something had gone wrong with the npm install, I went to the Kudu remote execution console and ran npm outdated. No packages are missing.

This is my server.js file:

const express = require('express');
const bodyParser = require('body-parser');
const app = express();

const port = process.env.port || 8000;

app.use(bodyParser.urlencoded({ extended: true }));

require('./app/routes')(app);
app.listen(port, () => {
});

I'm assuming it is something very obvious, but I can't work out what I'm missing.

3 Answers 3

2

Assuming your Azure App Service is Windows environment, try to include node_modules in the wwwroot.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

There isn't much we can really help with here, as the error you have provided indicates that the express npm package has not been installed properly. So, I would suggest that you use App Service Editor (https://[YouAppName].scm.azurewebsites.net/dev/wwwroot/) to troubleshoot this issue by checking whether the express folder exists in the node_module.

enter image description here

You can also run command npm install in the console, restart your app and run it (Ctrl + F5) in the browser.

enter image description here

1 Comment

In my case, it was because of failed deployment (Azure didn't notify though). You can go to Deployment options and check if it failed. Redeploying it seems to fix it.
0

check your package.json, it should have express included.

it should be similar to this

 "dependencies": {
    "@azure/storage-file-datalake": "^12.12.0",
    "express": "^4.18.2",
    "brotli": "^1.3.0",
    "bson": "^2.0.4",
    "int53": "^0.2.4",
    "object-stream": "0.0.1",
    "snappyjs": "^0.6.0",
    "thrift": "^0.10.0",
    "varint": "^5.0.0"
  }

Comments

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.