bug: top-level await issue

Open
#4,231 7 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
node.js, typescript
Domain
build-system

Research direction

Start with the linked reproduction repository and run npm run build using the reported Stencil, TypeScript, Rollup, and Node versions. Trace the build handling for the reproduced top-level await and the cjs module format. Done means the example builds successfully without the reported top-level-await error.

Written by the indexing model from the issue text.

Description

Bug: Validated
Prerequisites
Stencil Version

2.21.0

Current Behavior

Get build error when using top-level await.

"Module format cjs does not support top-level await."

Expected Behavior

Solution should build successfully.

System Info
System: node 14.17.1

    Compiler: \@stencil\core\compiler\stencil.js
     Stencil: 2.21.0
  TypeScript: 4.9.4
      Rollup: 2.42.3
      Parse5: 7.1.2
      Sizzle: 2.42.3
      Terser: 5.16.1
Steps to Reproduce

in ts file:
`export class Hello{
static async SayHello() {
return Promise.resolve('Hello World');
}
}

export const hello= await Profile.SayHello();
`

in another ts file import variable hello and use. Then build npm run build. You will receive the error.

Code Reproduction URL

Code

Additional Information

No response

Dominant language
TypeScript
Stars
13.1k
Forks
855
Avg merge
4h 7m
Merged PRs (30d)
44

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stenciljs/core

All issues in stenciljs/core

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.