2016-11-26 68 views
3

我試圖使用Webpack 1.13.12和eslint 3.11.0和eslint-plugin-promise 3.4.0。我試圖使用回答in this question讓Superagent產生Web服務調用的結果。「關鍵字收益率保留」eslint錯誤

import agent from 'superagent'; 
require('superagent-as-promised')(agent); 
import Promise from 'promise'; 

const API_URL = 'http://localhost/services/merchant'; 

export function createVendorCall() { 
    const responsePromise = yield Promise.resolve(agent.put(`${API_URL}/create`)); 

    let response = responsePromise.next(); 

    return response.body; 
} 

當我嘗試皮棉此,eslint抱怨The keyword 'yield' is reserved.我試過在我.eslintrc.json文件中設置require-yield爲0,但它仍然不會掉毛。使用內聯註釋來禁用eslint也不起作用。

我該怎麼辦?我是否以錯誤的方式使用Superagent,或者是否有必須禁用的規則?

編輯:這個問題被標記爲this question的副本。但是,這個問題沒有使用棉絨,而是有不同的錯誤信息。這裏的問題是eslint會將看起來有效的語法標記爲錯誤。

+1

'然而,這個問題沒有使用linter並且有不同的錯誤信息 - >除了它不是有效的語法,並且這兩個問題具有完全相同的原因。 – Carpetsmoker

+0

他們,對不起,我問。 – Brad

回答

1

嘗試添加*函數名所以這將是一臺發電機:

export function *createVendorCall() { 
    const responsePromise = yield Promise.resolve(agent.put(`${API_URL}/create`)); 

    let response = responsePromise.next(); 

    return response.body; 
} 

yield只應在發電機使用。

+0

現在它丟了,但它不會運行。當我在Chrome中運行這個時,我得到'Uncaught ReferenceError:regeneratorRuntime未定義(...)'。 – Brad

+0

@Brad這是一個特定的錯誤 - 一個非常好的搜索候選人。結果將回到相關的SO問題和答案。 – user2864740

+0

我嘗試使用問題的答案[這裏](http://stackoverflow.com/questions/28976748/regeneratorruntime-is-not-defined),[這裏](http://stackoverflow.com/questions/33527653/babel- 6-regeneratorruntime-is-not-defined-with-async-await)和[here](http://stackoverflow.com/questions/28976748/regeneratorruntime-is-not-defined),但似乎沒有解決該具體問題錯誤。 – Brad