我正在尝试通过this tutorial来学习webpack。
当我跑下午开始时,我得到70个错误。
$ npm start
> angular2-webpack@1.0.0 start /Users/angular-webpak
[at-loader] Using typescript@2.0.10 from typescript and "tsconfig.json" from /Users/angular-webpak/src/tsconfig.json.
[at-loader] Checking finished with 70 errors
...
ERROR in [at-loader] node_modules/@types/jasmine/index.d.ts:39:52
TS1005: '=' expected.
ERROR in [at-loader] node_modules/@angular/common/src/directives/ng_class.d.ts:48:34
TS2304: Cannot find name 'Set'.
ERROR in [at-loader] node_modules/@angular/common/src/pipes/async_pipe.d.ts:44:38
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/compiler/src/aot/compiler.d.ts:32:38
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/compiler/src/aot/compiler.d.ts:44:32
TS2304: Cannot find name 'Map'.
ERROR in [at-loader] node_modules/@angular/compiler/src/aot/compiler_host.d.ts:20:33
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/compiler/src/compile_metadata.d.ts:342:20
TS2304: Cannot find name 'Set'.
ERROR in [at-loader] node_modules/@angular/compiler/src/compile_metadata.d.ts:344:28
TS2304: Cannot find name 'Set'.
ERROR in [at-loader] node_modules/@angular/compiler/src/compile_metadata.d.ts:346:15
TS2304: Cannot find name 'Set'.
ERROR in [at-loader] node_modules/@angular/compiler/src/compile_metadata.d.ts:348:23
TS2304: Cannot find name 'Set'.
ERROR in [at-loader] node_modules/@angular/compiler/src/compile_metadata.d.ts:350:17
TS2304: Cannot find name 'Set'.
ERROR in [at-loader] node_modules/@angular/compiler/src/compile_metadata.d.ts:352:25
TS2304: Cannot find name 'Set'.
ERROR in [at-loader] node_modules/@angular/compiler/src/directive_normalizer.d.ts:38:72
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/compiler/src/directive_normalizer.d.ts:40:74
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/compiler/src/i18n/extractor.d.ts:14:33
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/compiler/src/i18n/extractor.d.ts:22:35
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/compiler/src/jit/compiler.d.ts:44:49
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/compiler/src/jit/compiler.d.ts:46:65
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/compiler/src/metadata_resolver.d.ts:58:104
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/compiler/src/output/output_ast.d.ts:433:63
TS2304: Cannot find name 'Set'.
ERROR in [at-loader] node_modules/@angular/compiler/src/resource_loader.d.ts:13:23
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/compiler/src/util.d.ts:33:18
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/compiler/src/util.d.ts:34:46
TS2304: Cannot find name 'Promise'.
<snipped several similar errors>
ERROR in [at-loader] node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts:24:15
TS2304: Cannot find name 'Map'.
ERROR in [at-loader] node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts:28:16
TS2304: Cannot find name 'Map'.
<snipped several similar errors>
ERROR in [at-loader] node_modules/@angular/platform-browser/src/dom/shared_styles_host.d.ts:11:30
TS2304: Cannot find name 'Set'.
ERROR in [at-loader] node_modules/@angular/platform-browser/src/dom/shared_styles_host.d.ts:22:30
TS2304: Cannot find name 'Set'.
ERROR in [at-loader] node_modules/@angular/router/src/config.d.ts:307:85
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/router/src/interfaces.d.ts:78:99
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/router/src/interfaces.d.ts:157:109
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/router/src/interfaces.d.ts:227:115
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/router/src/interfaces.d.ts:297:89
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/router/src/interfaces.d.ts:367:50
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/router/src/router.d.ts:392:70
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/router/src/router.d.ts:414:59
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@angular/router/src/utils/collection.d.ts:36:79
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/@types/jasmine/index.d.ts:39:38
TS2371: A parameter initializer is only allowed in a function or constructor implementation.
ERROR in [at-loader] node_modules/@types/jasmine/index.d.ts:39:46
TS2304: Cannot find name 'keyof'.
ERROR in [at-loader] node_modules/rxjs/Observable.d.ts:68:60
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/rxjs/Observable.d.ts:68:70
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/rxjs/observable/PromiseObservable.d.ts:40:31
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/rxjs/observable/PromiseObservable.d.ts:41:26
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/rxjs/operator/toPromise.d.ts:2:60
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/rxjs/operator/toPromise.d.ts:3:79
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] node_modules/rxjs/operator/toPromise.d.ts:3:89
TS2304: Cannot find name 'Promise'.
ERROR in [at-loader] src/app/app.component.ts:8:14
TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
ERROR in [at-loader] src/app/app.module.ts:13:14
TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
Child html-webpack-plugin for "index.html":
chunk {0} index.html 299 bytes [entry] [rendered]
Child extract-text-webpack-plugin:
chunk {0} extract-text-webpack-plugin-output-filename 1.95 kB [entry] [rendered]
webpack: Failed to compile.
答案 0 :(得分:8)
此修复程序位于https://github.com/angular/angular.io/pull/3233/commits/8e886fc2710acadd749139c2172519de254b849c
你必须修改webpack.common.js
答案 1 :(得分:2)
由于您正在使用Angular 2,因此您的案例中唯一可行的解决方案是将@types/jasmine
版本冻结为2.5.41
。
此外,您似乎在tsconfig.json
中没有 ES6 支持。
请参阅:https://stackoverflow.com/a/38212418/3472184。请注意lib
和target
属性。
答案 2 :(得分:1)
将tsconfig.json移至./src folder
。请参阅config/webpack.common.js
第7行:
options: {
configFileName: helpers.root('src', 'tsconfig.json')
}
将tsconfig.json更改为:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"types" : ["node"]
}
}
答案 3 :(得分:0)
@ user2995358为您的TS1219:设置实验设备&#39;删除此警告的选项。
将tsconfig.json从root
移到src文件夹