我正在使用 Node.js 构建一个 Web 应用程序。当 Node 4.0 版本发布时我就开始了。当我在本地计算机上运行 node -v
时,我看到:“v4.0.0”。我将该网站部署为 Microsoft Azure Web 应用程序。但是,这引入了 500 错误。
我查看了日志,看到以下内容:
Wed Sep 23 2015 13:29:20 GMT+0000 (Coordinated Universal Time): Unaught exception: SyntaxError: Unexpected reserved word
at Module._compile (module.js:439:25)
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)
at require (module.js:380:17)
at Object.<anonymous> (D:\home\site\wwwroot\routes\index.js:4:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
相关行使用了 class
关键字,这在 Node 4.0 中是允许的。这促使我检查 Azure Web 应用程序中运行的 Node 版本。我从 Azure 的控制台再次运行 node -v
。现在我看到“v0.10.32”。
如何为 Microsoft Azure Web App 运行 Node 4.0?
最佳答案
在 package.json 的“engines”指令中指定版本
{
"engines":{"node":4.0.0}
}
有关在此处指定版本的更多信息:https://azure.microsoft.com/en-us/documentation/articles/nodejs-specify-node-version-azure-apps/
关于node.js - 将 Node v4.0 用于 Windows Azure Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32741237/