[SWC] Module parse failed: The keyword 'yield' is reserved
See original GitHub issueWhat version of Next.js are you using?
12.0.4
What version of Node.js are you using?
14.16.0
What browser are you using?
Chrome 88
What operating system are you using?
macOS
How are you deploying your application?
other
Describe the Bug
Code with for
loop with await
inside throws error.
Expected Behavior
It should work, it is a valid JS
To Reproduce
Create a page like:
import { useEffect } from 'react';
async function injectExternalScripts() {
const list = ['https://external.com/x.js', 'https://external.com/y.js'];
for (const src of list) {
await new Promise((resolve, reject) => {
const s = document.createElement('script');
s.src = src;
s.onload = resolve;
s.onerror = reject;
document.body.appendChild(s);
});
}
}
export default function Home() {
useEffect( async() => {
await injectExternalScripts();
},[])
return (
<div>
<p>Hello World</p>
</div>
)
}
Run next build
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Module parse failed: The keyword 'yield' is reserved #31479
Describe the Bug npm run build fails with the following error: Module parse failed: The keyword 'yield' is reserved (453:107) File was ...
Read more >"The keyword yield is reserved" eslint error - Stack Overflow
Try adding a * to the function name so it will be a generator: export function *createVendorCall() { const responsePromise = yield ......
Read more >SyntaxError: The keyword 'yield' is reserved. Console Error in ...
I'm trying Nakama, a great game server for realtime multiplayer, and most of their Javascript client example code includes the use of ...
Read more >the keyword 'yield is reserved react native - Code Grepper
try to add `await` to function if not there already.
Read more >util.rs - source - SWC
Source of the Rust file `crates/swc_ecma_parser/src/parser/util.rs`. ... ("delete") => true, // Future reserved word js_word! ... false, Expr::Yield(.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@felixmosh use this https://www.npmjs.com/package/use-async-effect
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.