question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[SWC] Module parse failed: The keyword 'yield' is reserved

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
balazsorban44commented, Jan 27, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found