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

[Bug]: Top-level await not supported by remix/compiler #1355

Closed
vnikolov88 opened this issue Jan 5, 2022 · 2 comments
Closed

[Bug]: Top-level await not supported by remix/compiler #1355

vnikolov88 opened this issue Jan 5, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@vnikolov88
Copy link

vnikolov88 commented Jan 5, 2022

What version of Remix are you using?

v1.1.1

What version of Node are you using? Minimum supported version is 14.

v16.13.1

Steps to Reproduce

Changed the tsconfig.json to allow top-level await

"module": "es2022", "lib": ["DOM", "DOM.Iterable", "ES2019"], "target": "es2021",

and changed serverModuleFormat: "esm" in remix.config.js

the whole point is to have a top-level await in the db.server.ts file so when mongodb wants to connect it can do in a synchronous manner. also, it is interesting it is giving warnings for dotenv and MongoDB missing from the package.json as they are present and working properly although without the top-level await.

Expected Behavior

To work :D

Actual Behavior

[1] The path "dotenv" is imported in app\db.server.ts but dotenv is not listed in your package.json dependencies. Did you forget to install it?
[1] The path "mongodb" is imported in app\db.server.ts but mongodb is not listed in your package.json dependencies. Did you forget to install it?
[1]
[1] > app/db.server.ts:24:6: error: Top-level await is not available in the configured target environment ("es2021")
[1] 24 │ await global._mongoClient.connect();
[1] ╵ ~~~~~
[1] tsconfig.json:6:14: note: The target environment was set to "es2021" here
[1] 6 │ "target": "es2021",

@vnikolov88 vnikolov88 added the bug Something isn't working label Jan 5, 2022
@Paddy-Hamilton
Copy link

I was getting this error when running through the blog tutorial blog tutorial, seeding the db .

prisma/seed.ts:93:3 - 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.

I added your changes to the tsconfig.json and it's worked for me. Thanks.

Would be good to get this updated.

@machour
Copy link
Collaborator

machour commented Jan 22, 2023

Closed in favor of #4348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants