2017-01-24 70 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' –