简体   繁体   English

在严格模式下使用const:Azure Web App

[英]Use of const in strict mode : Azure Web App

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)

Error is thrown everytime Azure Web App project is made and an Express App is published. 每次创建Azure Web App项目并发布Express App都会引发错误。 I tried with Azure Express as well as Blank nodeJs App to do it 我尝试使用Azure Express以及Blank nodeJs App来做到这一点

Looks like it's caused by an invalid node version on Azure. 看来是由Azure上的无效节点版本引起的。 Go to Azure portal, your Web App - Application settings, check WEBSITE_NODE_DEFAULT_VERSION . 转到Azure门户(您的Web应用程序-应用程序设置),检查WEBSITE_NODE_DEFAULT_VERSION

Web应用程序节点版本

Once we specify a version not available on Azure, a quite old version 0.10.40 is in use, where const is not enabled by default so that we met SyntaxError: Use of const in strict mode . 一旦我们指定了Azure上不可用的版本,就会使用一个相当旧的版本0.10.40,默认情况下未启用const ,这样我们遇到了SyntaxError: Use of const in strict mode See related thread for more details. 有关更多详细信息,请参见相关线程

We can use 10.6.0, 8.11.1, etc. Go to https://<yourwebappname>.scm.azurewebsites.net/api/diagnostics/runtime to see all versions available. 我们可以使用10.6.0、8.11.1等。请访问https://<yourwebappname>.scm.azurewebsites.net/api/diagnostics/runtime以查看所有可用版本。

Caveat by Clinkz Clinkz警告

In some cases, the above solution may not work. 在某些情况下,上述解决方案可能不起作用。 This may be because your project includes the file iisnode.yml . 这可能是因为您的项目包含文件iisnode.yml If this file exists, it overrides application settings environment variable. 如果该文件存在,它将覆盖应用程序设置环境变量。 The content of this file should be as follows : 该文件的内容应如下:

nodeProcessCommandLine: "%SystemDrive%\Program Files (x86)\nodejs\0.10.4\node.exe"

The node version specified here takes precendence. 此处指定的节点版本优先。 To fix it, simply update the version, like so and deploy: 要修复它,只需更新版本,然后进行部署:

nodeProcessCommandLine: "%SystemDrive%\Program Files (x86)\nodejs\8.9.4\node.exe"

Refer to this . 参考这个


To conclude , the priority: iisnode.yml > package.json(engine)> Application settings. 最后 ,优先级为:iisnode.yml> package.json(engine)>应用程序设置。 Application setting is recommended as it's easy to check and modify on portal. 建议您设置应用程序,因为它很容易在门户网站上检查和修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM