i18next / i18next-http-backend

i18next-http-backend is a backend layer for i18next using in Node.js, in the browser and for Deno.
MIT License
452 stars 70 forks source link

Fails to build #158

Closed benweier closed 1 day ago

benweier commented 1 day ago

💥 Regression Report

My build now fails under v2.7.0

x Build failed in 1.83s
error during build:
[vite:esbuild-transpile] Transform failed with 1 error:
assets/index-!~{001}~.js:26522:16: ERROR: Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)

Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
26520|  if (!fetchApi && !XmlHttpRequestApi && !ActiveXObjectApi) {
26521|    try {
26522|      fetchApi = (await __vitePreload(async () => { const {default: __vite_default__} = await import('./!~{004}~.js').then(n => n.b);return { default: __vite_default__ }},true?__VITE_PRELOAD__:void 0)).default;
   |                  ^
26523|    } catch (e) {}
26524|  }

    at failureErrorWithLog (/Users/[...]/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:1472:15)
    at /Users/[...]/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:755:50
    at responseCallbacks.<computed> (/Users/[...]/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:622:9)
    at handleIncomingPacket (/Users/[...]/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:677:12)
    at Socket.readFromStdout (/Users/[...]/node_modules/.pnpm/esbuild@0.21.5/node_modules/esbuild/lib/main.js:600:7)
    at Socket.emit (node:events:520:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:191:23)
 ELIFECYCLE  Command failed with exit code 1.

Last working version

Worked up to version: 2.6.2

Stopped working in version: 2.7.0

To Reproduce

Steps to reproduce the behavior:

  1. Create a standard new Vite app with just the react plugin.
  2. Create main app file containing
import { I18nextProvider,  initReactI18next } from 'react-i18next'
import { createInstance } from 'i18next'
import backend from 'i18next-http-backend'

export const i18n = createInstance()

i18n
  .use(backend)
  .use(initReactI18next)
  .init({
    supportedLngs: ['en'],
    fallbackLng: 'en',
    load: 'languageOnly',
    defaultNS: 'common',
  })

export const App = () => {
  return <I18nextProvider i18n={i18n} />
}
  1. Run the build command

Builds fails. Downgrading to 2.6.2 works, and removing .use(backend) works.

Expected behavior

Build succeeds. 🙏

Your Environment

adrai commented 1 day ago

Have you tried to adapt the config? https://stackoverflow.com/questions/72618944/get-error-to-build-my-project-in-vite-top-level-await-is-not-available-in-the

that should do the trick:

image
adrai commented 1 day ago

Alternatively, change your import like this: import backend from 'i18next-http-backend/cjs'

benweier commented 1 day ago

Thanks for the info, and appreciate updating the changelog 👍

adrai commented 1 day ago

v2.7.0 has now been deprecated and v3.0.0 was released

benweier commented 1 day ago

That was quick 🤣