I created a project using create-react-app
but when I write some code with the keyword yield
, the page shows building error claiming 'Unexpected token' at yield
.
Is there a way to enable yield
in create-react-app
projects?
Did you forget to mark the function as a Generator by using the *
symbol?
function fn() {
yield "some value";
}
This code results in a syntax error, since the yield keyword is not allowed in normal functions.
function *generatorFn() {
yield "some value";
}
This code does not result in a syntax error, since the function is a generator.
For an example see this snippet