5

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.

Community
  • 1
  • 1
Brad
  • 2,261
  • 3
  • 22
  • 32

1 Answers1

2

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.

Eran Shabi
  • 14,201
  • 7
  • 30
  • 51
  • Now it lints, but it won't run. When I run this in Chrome I get `Uncaught ReferenceError: regeneratorRuntime is not defined(…)`. – Brad Nov 26 '16 at 17:56
  • @Brad That's a specific error - and a very good search candidate. Results will point back to relevant SO questions and answers. – user2864740 Nov 26 '16 at 17:57
  • I tried using answers for questions [here](http://stackoverflow.com/questions/28976748/regeneratorruntime-is-not-defined), [here](http://stackoverflow.com/questions/33527653/babel-6-regeneratorruntime-is-not-defined-with-async-await), and [here](http://stackoverflow.com/questions/28976748/regeneratorruntime-is-not-defined), but none seem to resolve that specific error. – Brad Nov 26 '16 at 18:07
  • In what line is the error? I think you are trying to run node code in the browser. – Eran Shabi Nov 26 '16 at 18:08
  • 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. – Brad Nov 26 '16 at 18:20