【问题标题】:Angular: Block-scoped declarations not yet supported outside strict mode in ChromeAngular:在 Chrome 的严格模式之外尚不支持块范围的声明
【发布时间】:2017-08-16 05:41:06
【问题描述】:

我正在关注Angular Tour of Heroes tutorial

加载应用程序 localhost:3000 后,我立即在 Chrome 浏览器 (v47) 中收到以下错误。相同的应用程序在 Firefox (v45) 中不会产生错误:

SyntaxError:块范围的声明(let、const、函数、类) 在 eval (native) 处尚不支持外部严格模式 SystemJSLoader.__exec (http://localhost:3000/node_modules/systemjs/dist/system.src.js:1555:18) 在 entry.execute (http://localhost:3000/node_modules/systemjs/dist/system.src.js:4035:18) 在链接动态模块 (http://localhost:3000/node_modules/systemjs/dist/system.src.js:3300:32) 在链接 (http://localhost:3000/node_modules/systemjs/dist/system.src.js:3135:11) 在 Object.execute (http://localhost:3000/node_modules/systemjs/dist/system.src.js:3510:13) 在 doDynamicExecute (http://localhost:3000/node_modules/systemjs/dist/system.src.js:766:25) 在链接 (http://localhost:3000/node_modules/systemjs/dist/system.src.js:964:20) 在 doLink (http://localhost:3000/node_modules/systemjs/dist/system.src.js:623:7) 在 updateLinkSetOnLoad (http://localhost:3000/node_modules/systemjs/dist/system.src.js:669:18) 在 http://localhost:3000/node_modules/systemjs/dist/system.src.js:485:11 在 ZoneDelegate.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:334:26) 在 区域运行 (http://localhost:3000/node_modules/zone.js/dist/zone.js:126:43) 在 http://localhost:3000/node_modules/zone.js/dist/zone.js:713:57 在 ZoneDelegate.invokeTask (http://localhost:3000/node_modules/zone.js/dist/zone.js:367:31)

这是正在使用的 tsconfig.json 文件(在教程中提供):

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es2015", "dom" ],
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  }
}

【问题讨论】:

    标签: javascript google-chrome angular


    【解决方案1】:

    尝试将"alwaysStrict":true 添加到您的 tsconfig。正如它错误所说,您需要使用严格模式,此选项将为您完成。

    'use strict';
    

    【讨论】:

    • 'use strict' 被添加到编译的 JavaScript 文件中,但遗憾的是报告了同样的错误
    猜你喜欢
    • 2017-06-17
    • 2019-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-02
    • 2023-04-07
    • 2016-01-05
    相关资源
    最近更新 更多