Error in user YAML: (<unknown>): found character that cannot start any token while scanning for the next token at line 2 column 8
---
id: babel-plugin-syntax-top-level-await
title: @babel/plugin-syntax-top-level-await
sidebar_label: syntax-top-level-await
---
This plugin only enables parsing of this feature. Babel doesn't support transforming top-level await, but you can use Rollup's
experimentalTopLevelAwait
or webpack@5'sexperiments.topLevelAwait
options.
const val = await promise;
export { val };
npm install --save-dev @babel/plugin-syntax-top-level-await
.babelrc
{
"plugins": ["@babel/plugin-syntax-top-level-await"]
}
babel --plugins @babel/plugin-syntax-top-level-await script.js
require("@babel/core").transform("code", {
plugins: ["@babel/plugin-syntax-top-level-await"],
});