Skip to content

Top-Level Await error with vite even with target: 'esnext' #57

@mikericher

Description

@mikericher

🐛 Bug Report

A top-level await error from this dependency.

vite built, remix.run app (with transitions to react-router-v7), with i18next / i18next-fs-backend / etc.

Original i18next-fs-backend: 2.3.2
Updated dep to the latest 2.6.0 (also tried 2.4.0)

This causes the following error:
[ERROR] Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)

node_modules/i18next-fs-backend/esm/readFile.js:8:20:
  8 │ var fs = !isDeno ? (await import('node:fs')).default : undefined;

vite.config.ts has the build target set to { target: 'esnext' }
tried with initAsync: false

Note: I am able to use top-level await in all my remaining code (including await i18n.getLocale (when using 2.3.2)...
Downgrade dep to 2.3.2 works fine

Suspect the dependency's i18next-fs-backend tsconfig.json target. You need at least es2022 for top-level-await support.
Suspect esm build broken.
Although, I have no clue when it comes to multiple build systems, typescript support, etc.

In addition to the base functionality of ES2015/ES6, ES2020 adds support for dynamic imports, and import.meta while ES2022 further adds support for top level await.

Expected behavior

To use i18next-fs-backend without error in a top-level-await environment

Your Environment

"@remix-run/express": "2.15.0",
"@remix-run/node": "2.15.0",
"@remix-run/react": "2.15.0",
"@remix-run/serve": "2.15.0",
"@remix-run/server-runtime": "2.15.0",
"@remix-run/dev": "2.15.0",
"@remix-run/fs-routes": "^2.15.0",
"@remix-run/route-config": "^2.15.0",
"@remix-run/routes-option-adapter": "^2.15.0",
"remix-i18next": "6.4.1",
"i18next": "^24.0.0",
"i18next-browser-languagedetector": "^8.0.0",
"i18next-fs-backend": "^2.6.0",
"i18next-http-backend": "^3.0.1",
"vite": "^5.4.11",
"vite-tsconfig-paths": "^5.1.3",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions