Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.5 nightly nodenext does not allow top-level await (anymore?) #46869

Closed
simllll opened this issue Nov 19, 2021 · 7 comments
Closed

4.5 nightly nodenext does not allow top-level await (anymore?) #46869

simllll opened this issue Nov 19, 2021 · 7 comments
Assignees
Labels
Bug A bug in TypeScript Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@simllll
Copy link
Contributor

simllll commented Nov 19, 2021

Bug Report

I just switched to 4.5 nightly due to the change in the release of 4.5 with node12 and nodenext and tried to work on my esm branch to get things running again, but somehow 4.5 nightly ( "typescript": "^4.6.0-dev.20211119") does not allow top-level await anymore, even though it says:
error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher.

my ts config has

"module": "nodenext",
  "target": "es2021",

it also does not work with node12 (obviously) or other target settings. It does work with module esnext though

🔎 Search Terms

nodenext, top-level await

🕗 Version & Regression Information

I'm not 100% sure, but I believe it worked in the ts4.5 alpha already.

  • This is a crash

🙁 Actual behavior

cannot compile something like this

// @hokify/schedular is an ESM module
const { AgendaScheduler } = await import('@hokify/scheduler');

in top-level code.

🙂 Expected behavior

should compile

@simllll simllll changed the title 4.5 nightly node12 / nodenext does not allow top-level await anymore 4.5 nightly nodenext does not allow top-level await anymore Nov 19, 2021
@simllll simllll changed the title 4.5 nightly nodenext does not allow top-level await anymore 4.5 nightly nodenext does not allow top-level await (anymore?) Nov 19, 2021
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Nov 19, 2021
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.5.2 milestone Nov 19, 2021
@RyanCavanaugh
Copy link
Member

@rbuckton this looks like something we'll need to patch

@DanielRosenwasser
Copy link
Member

Why patch? It's not part of TypeScript 4.5, it's just something that would go into the nightly, right?

@DanielRosenwasser
Copy link
Member

(feel free to re-milestone if I'm wrong!)

@RyanCavanaugh
Copy link
Member

Oops, I misread the version being tested

@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label May 13, 2022
@rbuckton
Copy link
Member

@simllll: I cannot repro this. Is your project configured correctly? Top-level await is only supported in --module nodenext when the input file is an ES module, not a CommonJS module. I tested this with both an .mts source file and with a .ts file in a folder with a package.json containing { "type": "module" }.

In 4.7 we changed the error message to error TS1309: The current file is a CommonJS module and cannot use 'await' at the top level. to clarify what's wrong.

@rbuckton
Copy link
Member

I should note, I tested against the following TS versions:

  • typescript@4.5.0-dev.20211101
  • typescript@4.6.0-dev.20211102
  • typescript@4.7
  • typescript@4.8

All supported top-level await correctly when the source file will be treated as a module and not as a CommonJS file.

@rbuckton
Copy link
Member

@simllll Is this still an issue for you? As I mentioned a few months ago, I haven't been able to repro this. I'm going to close this, but I'll reopen if you have a repro against a recent version of the compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

No branches or pull requests

4 participants