【问题标题】:Use of const in strict mode : Azure Web App在严格模式下使用 const :Azure Web App
【发布时间】:2019-01-31 05:45:31
【问题描述】:
Application has thrown an uncaught exception and is terminated: SyntaxError: Use of const in strict mode.
at Module._compile (module.js:434:25)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (D:\home\site\wwwroot\node_modules\mongoose\index.js:7:18)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
每次创建 Azure Web App 项目并发布 Express App 时都会引发错误。我尝试使用 Azure Express 和 Blank nodeJs App 来做到这一点
【问题讨论】:
标签:
node.js
azure
azure-web-app-service
【解决方案1】:
看起来这是由 Azure 上的无效节点版本引起的。转到 Azure 门户,您的 Web 应用程序 - 应用程序设置,检查 WEBSITE_NODE_DEFAULT_VERSION。
一旦我们指定了 Azure 上不可用的版本,就会使用相当旧的 0.10.40 版本,其中 const 默认未启用,因此我们遇到了 SyntaxError: Use of const in strict mode。详情请见related thread。
我们可以使用 10.6.0、8.11.1 等。转到 https://<yourwebappname>.scm.azurewebsites.net/api/diagnostics/runtime 以查看所有可用版本。
Clinkz 的警告
在某些情况下,上述解决方案可能不起作用。这可能是因为您的项目包含文件iisnode.yml。如果此文件存在,它将覆盖应用程序设置环境变量。这个文件的内容应该如下:
nodeProcessCommandLine: "%SystemDrive%\Program Files (x86)\nodejs\0.10.4\node.exe"
此处指定的节点版本优先。要修复它,只需更新版本,就像这样并部署:
nodeProcessCommandLine: "%SystemDrive%\Program Files (x86)\nodejs\8.9.4\node.exe"
请参阅this。
总结,优先级:iisnode.yml > package.json(engine)> 应用设置。推荐应用设置,方便在门户上查看和修改。