Skip to main content
deleted 62 characters in body
Source Link
T.J. Crowder
  • 1.1m
  • 19
  • 110
  • 139

It's a Stack Snippets bugUpdate: This is fixed as of Oct 3 2024, see the updates in this bug report (butwhich SE won't call it a bug, they call itcalled a "feature request"), please see this question.

 

The problem is that the version of babel-standalone used by Stack Snippets is (well) out of date and doesn't understand async/await. Amusingly, on any modern browser, if you untick the Babel box in the snippet, it'll work. But if you want JSX compilation, you need to tick the box, so using async in (say) a React question won't work.

It also works if you use a current version of babel-standalone, like this:

<script src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script type="text/babel">
function bar() {
  return new Promise((resolve,reject) => {
    setTimeout(()=> {
      resolve('resolved after 1500ms');
    },1500);
    // return resolve('resolved');
  });
}

async function foo() {
  const result = await bar();
  console.log(result);
}

foo();
</script>

Note that you can't put the code that Babel will process in the JavaScript panel in the snippet editor. You have to put it in the HTML panel instead, in a <script type="text/babel">...</script> tag.

It's a Stack Snippets bug (but SE won't call it a bug, they call it a "feature request"), please see this question.

The problem is that the version of babel-standalone used by Stack Snippets is (well) out of date and doesn't understand async/await. Amusingly, on any modern browser, if you untick the Babel box in the snippet, it'll work. But if you want JSX compilation, you need to tick the box, so using async in (say) a React question won't work.

It also works if you use a current version of babel-standalone, like this:

<script src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script type="text/babel">
function bar() {
  return new Promise((resolve,reject) => {
    setTimeout(()=> {
      resolve('resolved after 1500ms');
    },1500);
    // return resolve('resolved');
  });
}

async function foo() {
  const result = await bar();
  console.log(result);
}

foo();
</script>

Note that you can't put the code that Babel will process in the JavaScript panel in the snippet editor. You have to put it in the HTML panel instead, in a <script type="text/babel">...</script> tag.

Update: This is fixed as of Oct 3 2024, see the updates in this bug report (which SE called a "feature request").

 

The problem is that the version of babel-standalone used by Stack Snippets is (well) out of date and doesn't understand async/await. Amusingly, on any modern browser, if you untick the Babel box in the snippet, it'll work. But if you want JSX compilation, you need to tick the box, so using async in (say) a React question won't work.

It also works if you use a current version of babel-standalone, like this:

<script src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script type="text/babel">
function bar() {
  return new Promise((resolve,reject) => {
    setTimeout(()=> {
      resolve('resolved after 1500ms');
    },1500);
    // return resolve('resolved');
  });
}

async function foo() {
  const result = await bar();
  console.log(result);
}

foo();
</script>

Note that you can't put the code that Babel will process in the JavaScript panel in the snippet editor. You have to put it in the HTML panel instead, in a <script type="text/babel">...</script> tag.

added 243 characters in body
Source Link
T.J. Crowder
  • 1.1m
  • 19
  • 110
  • 139

It's a Stack Snippets bug (but SE won't call it a bug, they call it a "feature request"), please see this question.

The problem is that the version of babel-standalone used by Stack Snippets is (well) out of date and doesn't understand async/await. Amusingly, on any modern browser, if you untick the Babel box in the snippet, it'll work. But if you want JSX compilation, you need to tick the box, so using async in (say) a React question won't work.

It also works if you use a current version of babel-standalone, like this:

<script src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script type="text/babel">
function bar() {
  return new Promise((resolve,reject) => {
    setTimeout(()=> {
      resolve('resolved after 1500ms');
    },1500);
    // return resolve('resolved');
  });
}

async function foo() {
  const result = await bar();
  console.log(result);
}

foo();
</script>

Note that you can't put the code that Babel will process in the JavaScript panel in the snippet editor. You have to put it in the HTML panel instead, in a <script type="text/babel">...</script> tag.

The problem is that the version of babel-standalone used by Stack Snippets is (well) out of date and doesn't understand async/await. Amusingly, on any modern browser, if you untick the Babel box in the snippet, it'll work. But if you want JSX compilation, you need to tick the box, so using async in (say) a React question won't work.

It also works if you use a current version of babel-standalone, like this:

<script src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script type="text/babel">
function bar() {
  return new Promise((resolve,reject) => {
    setTimeout(()=> {
      resolve('resolved after 1500ms');
    },1500);
    // return resolve('resolved');
  });
}

async function foo() {
  const result = await bar();
  console.log(result);
}

foo();
</script>

Note that you can't put the code that Babel will process in the JavaScript panel in the snippet editor. You have to put it in the HTML panel instead, in a <script type="text/babel">...</script> tag.

It's a Stack Snippets bug (but SE won't call it a bug, they call it a "feature request"), please see this question.

The problem is that the version of babel-standalone used by Stack Snippets is (well) out of date and doesn't understand async/await. Amusingly, on any modern browser, if you untick the Babel box in the snippet, it'll work. But if you want JSX compilation, you need to tick the box, so using async in (say) a React question won't work.

It also works if you use a current version of babel-standalone, like this:

<script src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script type="text/babel">
function bar() {
  return new Promise((resolve,reject) => {
    setTimeout(()=> {
      resolve('resolved after 1500ms');
    },1500);
    // return resolve('resolved');
  });
}

async function foo() {
  const result = await bar();
  console.log(result);
}

foo();
</script>

Note that you can't put the code that Babel will process in the JavaScript panel in the snippet editor. You have to put it in the HTML panel instead, in a <script type="text/babel">...</script> tag.

added 114 characters in body
Source Link
T.J. Crowder
  • 1.1m
  • 19
  • 110
  • 139

The problem is that the version of babel-standalone used by Stack Snippets is (well) out of date and doesn't understand async/await. Amusingly, on any modern browser, if you untick the Babel box in the snippet, it'll work. But if you want JSX compilation, you need to tick the box, so using async in (say) a React question won't work.

It also works if you use a current version of babel-standalone, like this:

<script src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script type="text/babel">
function bar() {
  return new Promise((resolve,reject) => {
    setTimeout(()=> {
      resolve('resolved after 1500ms');
    },1500);
    // return resolve('resolved');
  });
}

async function foo() {
  const result = await bar();
  console.log(result);
}

foo();
</script>

Note that you can't put the code that Babel will process in the JavaScript panel in the snippet editor. You have to put it in the HTML panel instead, in a <script type="text/babel">...</script> tag.

The problem is that the version of babel-standalone used by Stack Snippets is (well) out of date and doesn't understand async/await. Amusingly, on any modern browser, if you untick the Babel box in the snippet, it'll work.

It also works if you use a current version of babel-standalone, like this:

<script src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script type="text/babel">
function bar() {
  return new Promise((resolve,reject) => {
    setTimeout(()=> {
      resolve('resolved after 1500ms');
    },1500);
    // return resolve('resolved');
  });
}

async function foo() {
  const result = await bar();
  console.log(result);
}

foo();
</script>

Note that you can't put the code that Babel will process in the JavaScript panel in the snippet editor. You have to put it in the HTML panel instead, in a <script type="text/babel">...</script> tag.

The problem is that the version of babel-standalone used by Stack Snippets is (well) out of date and doesn't understand async/await. Amusingly, on any modern browser, if you untick the Babel box in the snippet, it'll work. But if you want JSX compilation, you need to tick the box, so using async in (say) a React question won't work.

It also works if you use a current version of babel-standalone, like this:

<script src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script type="text/babel">
function bar() {
  return new Promise((resolve,reject) => {
    setTimeout(()=> {
      resolve('resolved after 1500ms');
    },1500);
    // return resolve('resolved');
  });
}

async function foo() {
  const result = await bar();
  console.log(result);
}

foo();
</script>

Note that you can't put the code that Babel will process in the JavaScript panel in the snippet editor. You have to put it in the HTML panel instead, in a <script type="text/babel">...</script> tag.

Call out that you have to use a script type="text/babel" tag for it to work with babel standalone
Source Link
T.J. Crowder
  • 1.1m
  • 19
  • 110
  • 139
Loading
updated standalone Babel link to 7; moved the external Babel inclusion above the custom code
Source Link
3limin4t0r
  • 21k
  • 10
  • 5
Loading
deleted 62 characters in body
Source Link
T.J. Crowder
  • 1.1m
  • 19
  • 110
  • 139
Loading
Post Migrated Here from stackoverflow.com (revisions)
Source Link
T.J. Crowder
  • 1.1m
  • 19
  • 110
  • 139
Loading