我正在浏览AngularJS的教程。代码可以在https://github.com/planetoftheweb/learnangular/tree/02_01e发现 我正在使用这个代码。当我运行npm start时,我收到此错误:
node_modules/@angular/common/src/pipes/async_pipe.d.ts(39,38): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/directive_normalizer.d.ts(19,100): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/directive_normalizer.d.ts(21,74): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/offline_compiler.d.ts(31,124): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/resource_loader.d.ts(13,23): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/runtime_compiler.d.ts(40,49): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/runtime_compiler.d.ts(42,65): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/util.d.ts(35,18): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/compiler/src/util.d.ts(36,46): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_init.d.ts(16,18): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(106,67): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(122,101): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(148,67): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/application_ref.d.ts(150,101): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/facade/lang.d.ts(12,17): error TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/facade/lang.d.ts(13,17): error TS2304: Cannot find name 'Set'.
node_modules/@angular/core/src/linker/compiler.d.ts(53,49): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/linker/compiler.d.ts(61,65): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/linker/ng_module_factory_loader.d.ts(14,34): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/core/src/linker/system_js_ng_module_factory_loader.d.ts(28,25): error TS2304: Cannot find name 'Promise'.
node_modules/@angular/platform-browser-dynamic/src/resource_loader/resource_loader_impl.d.ts(10,23): error TS2304: Cannot find name 'Promise'.
node_modules/@types/core-js/index.d.ts(47,36): error TS2304: Cannot find name 'Iterable'.
node_modules/@types/core-js/index.d.ts(353,48): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(354,52): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(355,34): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(356,34): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(357,34): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(358,61): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(359,60): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(360,65): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(360,97): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(361,60): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(362,58): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(363,59): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(364,58): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(365,61): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(365,117): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(366,42): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(368,81): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(369,78): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(370,76): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(371,73): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(434,6): error TS2304: Cannot find name 'Symbol'.
node_modules/@types/core-js/index.d.ts(459,39): error TS2304: Cannot find name 'Promise'.
node_modules/@types/core-js/index.d.ts(467,59): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(468,59): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(470,48): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(471,69): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(475,40): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(477,48): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(693,55): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(694,45): error TS2304: Cannot find name 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(710,46): error TS2304: Cannot find name 'Iterable'.
node_modules/@types/core-js/index.d.ts(711,43): error TS2304: Cannot find name 'Iterable'.
node_modules/@types/core-js/index.d.ts(826,20): error TS2304: Cannot find name 'PromiseConstructor'.
node_modules/@types/core-js/index.d.ts(841,32): error TS2304: Cannot find name 'Iterable'.
node_modules/@types/core-js/index.d.ts(845,39): error TS2304: Cannot find name 'Iterable'.
node_modules/@types/core-js/index.d.ts(845,53): error TS2304: Cannot find name 'Iterator'.
node_modules/@types/core-js/index.d.ts(856,35): error TS2304: Cannot find name 'Promise'.
node_modules/@types/core-js/index.d.ts(1479,36): error TS2339: Property 'for' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(1483,43): error TS2339: Property 'hasInstance' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(1487,50): error TS2339: Property 'isConcatSpreadable' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(1491,40): error TS2339: Property 'iterator' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(1495,38): error TS2339: Property 'keyFor' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(1499,37): error TS2339: Property 'match' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(1503,39): error TS2339: Property 'replace' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(1507,38): error TS2339: Property 'search' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(1511,39): error TS2339: Property 'species' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(1515,37): error TS2339: Property 'split' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(1519,43): error TS2339: Property 'toPrimitive' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(1523,43): error TS2339: Property 'toStringTag' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(1527,43): error TS2339: Property 'unscopables' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2294,36): error TS2339: Property 'for' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2298,43): error TS2339: Property 'hasInstance' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2302,50): error TS2339: Property 'isConcatSpreadable' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2306,40): error TS2339: Property 'iterator' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2310,38): error TS2339: Property 'keyFor' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2314,37): error TS2339: Property 'match' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2318,39): error TS2339: Property 'replace' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2322,38): error TS2339: Property 'search' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2326,39): error TS2339: Property 'species' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2330,37): error TS2339: Property 'split' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2334,43): error TS2339: Property 'toPrimitive' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2338,43): error TS2339: Property 'toStringTag' does not exist on type 'SymbolConstructor'.
node_modules/@types/core-js/index.d.ts(2342,43): error TS2339: Property 'unscopables' does not exist on type 'SymbolConstructor'.
node_modules/rxjs/Observable.d.ts(10,66): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(66,60): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(66,70): error TS2304: Cannot find name 'Promise'.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! learn-angular@1.0.0 start: `tsc && concurrently "tsc -w" "lite-server" `
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the learn-angular@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/craigbertrand/.npm/_logs/2017-11-06T15_09_02_610Z-debug.log
运行npm -v
日志5.5.1
如果我将tsconfig.json
形式es5中的目标更改为es6,一切正常。
不过,我在其他地方读过,目标es5基本上是标准的,如果你以es6为目标,那么你就有可能不支持旧的浏览器。这仍然是真的吗?如果是不好的做法,那么什么是更好的解决方案?
答案 0 :(得分:0)
在GitHub存储库中有一个issue。其中一条评论给出了一个似乎适用于少数人的解决方案:
...通过将此行添加到我的tsconfig.json文件中解决了这个问题
"lib" : ["es2015", "es2015.iterable", "dom"]
正如您所建议的那样,定位ES5可提供更好的浏览器支持。一旦您定位ES6,您将需要一个支持ES6的浏览器,根据您的受众,这可能是也可能不是问题。就个人而言,我会将ES5作为更高兼容性的目标。