Azure/Node.js Unaught exception: Error: Cannot find module 'ms'

亡梦爱人 提交于 2020-01-05 14:04:53

问题


I’ve deployed a small node.js app that runs fine locally in visual studio 2015 to Azure using the Azure publish option (right click – publish – azure profile etc.). However, when I visit the site all I get on the page is:

The page cannot be displayed because an internal server error has occurred.

If I connect VS server explorer up to the Azure instance to view the logs, inside logging-errors.txt I can see the following logged lots of times:

Wed Jul 29 2015 12:22:36 GMT+0000 (Coordinated Universal Time): Unaught exception: Error: Cannot find module 'ms'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (D:\home\site\wwwroot\node_modules\debug\debug.js:14:20)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

This is a brand new web app provisioned via the preview portal.

There is no ‘ms’ package defined either in my project dependencies or in the node_modules folder, so I'm assuming this is a Microsoft/Azure specific package required for hosting on Azure.

Have I missed a step in “preparing” my node app for Azure, or is there some other configuarion step I need to perform?

Thanks


回答1:


It looks like it's having trouble loading modules. Do you have a package.json file that defines your dependencies? The default deployment script that Azure runs when you deploy your site will look for a package.json and perform an npm install --production. That means it will install everything you've defined as in 'dependencies' but not the packages you've defined as 'devDependencies'.




回答2:


To debug node apps deployed to Azure that won't startup I do:

  • Open a Powershell on it's scm (https://.scm.azurewebsites.net/DebugConsole/?shell=powershell)
  • Check your node is set correctly node --version
  • Attempt to start it and look at errors node .\server.js (or whatever is specified in your package.json > start script.

It would be nice if you could see such a log for when Azure starts the app. However I have not found it.



来源:https://stackoverflow.com/questions/31700589/azure-node-js-unaught-exception-error-cannot-find-module-ms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!