i18next-http-backend: Cloudflare Worker/Pages endless init

πŸ› Bug Report

Awaiting the result of init() never finishes on Cloudflare Workers. There is no exception, it simply does never finish.

To Reproduce

The following code displays the behaviour:

    const instance = createInstance();
    await instance
        .use(initReactI18next)
        .use(Backend)
        .init({
            ns: ['common'],
            lng: 'en-US',
            react: {suspense: false},
            backend: {
                loadPath: `${baseUrl}${i18n.backend.loadPath}`
            }
        });

My assumption is that there is an exception outside the fetch handler/promise and that this causes the passed in callback here: https://github.com/i18next/i18next-http-backend/blob/84c188dce4353d639b64f66831d579aaa6ee2b73/lib/request.js#L109 to never be called, hence never completing the promise returned from init.

Using a very simplified handler, solves the problem:

            backend: {
                loadPath: `${baseUrl}${i18n.backend.loadPath}`,
                request: (options, url, payload, callback) => {
                    fetch(url).then(response => response.text()).then(data => callback(null, { status: response.status, data })
                }
            }

Unfortunately I couldnt debug this further where it crashes. I haven’t figured out how I would find such exception yet, because this does work locally with wrangler dev/wrangler pages dev (the local test env for Cloudflare Workers).

Runtime: Cloudflare Workers Version: 1.4.1

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (8 by maintainers)

Commits related to this issue

Most upvoted comments

If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project.

There are many ways to help this project πŸ™

v1.4.4? πŸ˜‰