"The keyword yield is reserved" eslint error

10,386

Try adding a * to the function name so it will be a generator:

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

    let response = responsePromise.next();

    return response.body;
}

yield should be used only in generators.

Share:
10,386

Related videos on Youtube

Brad
Author by

Brad

Updated on June 04, 2022

Comments

  • Brad
    Brad almost 2 years

    I'm attempting to use Webpack 1.13.12 and eslint 3.11.0 and eslint-plugin-promise 3.4.0. I'm trying to use the answer in this question to get Superagent to yield the result of a web service call.

    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;
    }
    

    When I attempt to lint this, eslint complains that The keyword 'yield' is reserved. I've tried setting require-yield to 0 in my .eslintrc.json file, but it still won't lint. Using inline comments to disable eslint doesn't work either.

    What should I do? Am I using Superagent the wrong way, or is there a rule I have to disable?

    EDIT: This question was marked as a duplicate of this question. That question, however, was not using a linter and had a different error message. The problem here is that eslint is flagging what appears to be valid syntax as an error.

    • Martin Tournoij
      Martin Tournoij over 7 years
      That question, however, was not using a linter and had a different error message -> Except that it's not valid syntax, and that both questions have exactly the same cause.
  • Brad
    Brad over 7 years
    Now it lints, but it won't run. When I run this in Chrome I get Uncaught ReferenceError: regeneratorRuntime is not defined(…).
  • user2864740
    user2864740 over 7 years
    @Brad That's a specific error - and a very good search candidate. Results will point back to relevant SO questions and answers.
  • Brad
    Brad over 7 years
    I tried using answers for questions here, here, and here, but none seem to resolve that specific error.
  • Eran Shabi
    Eran Shabi over 7 years
    In what line is the error? I think you are trying to run node code in the browser.
  • Brad
    Brad over 7 years
    For the Reference Error? It's in the bundle.js code. The project is a node project, but all the code in question is running in the browser, not the server. If you mean the original eslint error, that runs as part of the build in package.json, which I can post if you like.