2017-01-24 40 views
4

我想使用异步/等待功能与angular2-webpack-starertypescript(现在有这个功能针对ES5的支持),但我发现了错误: enter image description here异步/ AWAIT __generator没有定义

这是组件内的代码:

// function inside component 
async checkSlug(slug: string) { 
     // nothing here 
} 

我正在使用webpack2.2和typescript 2.1.5。这是我的tsconfig:

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "allowSyntheticDefaultImports": true, 
    "sourceMap": true, 
    "noEmit": true, 
    "noEmitHelpers": true, 
    "strictNullChecks": false, 
    "baseUrl": "./src", 
    "paths": { 
    }, 
    "lib": [ 
     "dom", 
     "es7", 
     "es2015.promise" 
    ], 
    "types": [ 
     "hammerjs", 
     "jasmine", 
     "node", 
     "protractor", 
     "selenium-webdriver", 
     "source-map", 
     "uglify-js", 
     "webpack", 
     "chai", 
     "chai-as-promised", 
     "lodash" 
    ] 
    }, 
    "exclude": [ 
    "node_modules", 
    "dist" 
    ], 
    "awesomeTypescriptLoaderOptions": { 
    "forkChecker": true, 
    "useWebpackText": true 
    }, 
    "compileOnSave": false, 
    "buildOnSave": false, 
    "atom": { "rewriteTsconfig": false } 
} 
+2

你告诉编译器不产生辅助功能为你' “noEmitHelpers”:TRUE'。如果你将它设置为false,它应该工作。否则,你需要提供帮助功能。见https://blog.mariusschulz.com/2016/12/16/typescript-2-1-external-helpers-library – JohnnyHK

回答

3

好吧,这tsconfig.json工作

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "allowSyntheticDefaultImports": true, 
    "sourceMap": true, 
    "noEmit": true, 
    "noEmitHelpers": false, 
    "strictNullChecks": false, 
    "baseUrl": "./src", 
    "paths": { 
    }, 
    "lib": [ 
     "dom", 
     "es7", 
     "es5", 
     "es2015.promise" 
    ], 
    "types": [ 
     "hammerjs", 
     "jasmine", 
     "node", 
     "protractor", 
     "selenium-webdriver", 
     "source-map", 
     "uglify-js", 
     "webpack", 
     "chai", 
     "chai-as-promised", 
     "lodash" 
    ] 
    }, 
    "exclude": [ 
    "node_modules", 
    "dist" 
    ], 
    "awesomeTypescriptLoaderOptions": { 
    "forkChecker": true, 
    "useWebpackText": true 
    }, 
    "compileOnSave": false, 
    "buildOnSave": false, 
    "atom": { "rewriteTsconfig": false } 
} 
+1

这个答案更清晰的解决方案:https://stackoverflow.com/a/42426996/1569600 'noEmitHelpers:false' –