Pnpjs: Typescript error: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext'...

Created on 16 Jul 2020  路  2Comments  路  Source: pnp/pnpjs

Hello, thanks for creating this, I麓m trying to test the library on a project build with yeoman, react, and typescript, but I get the following TS error that blocks me

Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.

import { graph } from "@pnp/graph";
import { GroupType } from '@pnp/graph/groups';

const groupAddResult = await graph.groups.add("GroupName", "Mail_NickName", GroupType.Office365);
const group = await groupAddResult.group();

Is there a workaround for this?

Thanks

non-library answered question

Most helpful comment

Top-level awaits require a specific build configuration and not available by default in most of the pipelines.
For the time being, awaits are better be used in async functions.

const foo = async () => {
  const bar = await baz();
  // do smt with bar
};

All 2 comments

Top-level awaits require a specific build configuration and not available by default in most of the pipelines.
For the time being, awaits are better be used in async functions.

const foo = async () => {
  const bar = await baz();
  // do smt with bar
};

Cool, thanks

Was this page helpful?
0 / 5 - 0 ratings