Registry / i18n / i18next-fetch-backend

i18next-fetch-backend

JSON →
library7.0.0jsnpmunverified

v7.0.0: A backend plugin for i18next that loads translation resources using the browser's Fetch API, suitable for modern browsers and Service Worker contexts. The package ships TypeScript types and requires Node >=20. It replaces XMLHttpRequest-based backends, offering native promise support and compatibility with fetch options like CORS and credentials. Release cadence is irregular; the latest major version removed deprecated callback-based fetch in favor of a function returning a Promise.

npm install i18next-fetch-backend
INSTALL
IMPORT
SIG · I18NEXT-FETCH-BACK
I
i18next-fetch-backend
i18njavascriptv7.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Fetch
import Fetch from 'i18next-fetch-backend'
const Fetch = require('i18next-fetch-backend')
Default import only. CommonJS require is not supported as the package is ESM-only since v7.
Fetch (type)
import type { FetchBackendOptions } from 'i18next-fetch-backend'
Use `import type` for TypeScript to avoid emitting runtime code.

Demonstrates basic initialization of i18next with the fetch backend, loading translations from /locales/{{lng}}/{{ns}}.json with CORS options.

import i18next from 'i18next'; import Fetch from 'i18next-fetch-backend'; i18next .use(Fetch) .init({ fallbackLng: 'en', backend: { loadPath: '/locales/{{lng}}/{{ns}}.json', requestOptions: { mode: 'cors', credentials: 'same-origin' } } }, (err, t) => { if (err) return console.error(err); console.log(t('key')); });
Debug
Known issues
breakingv7 dropped support for Node <20 and CommonJS (require). Use ESM imports and Node >=20.
fix
Update Node to >=20 and migrate from `require` to `import`.
affects: >=7.0.0
breakingv7 changed the `fetch` option signature: now it must return a Promise instead of using a callback.
fix
Replace `fetch: function(url, options, callback) { ... callback(null, data); }` with `fetch: async (url, options) => { ... return data; }`.
affects: >=7.0.0
deprecatedThe `allowMultiLoading` option is deprecated; use multi-namespace loading via i18next options instead.
fix
Refer to i18next documentation for multiloading patterns.
affects: >=5.0.0
gotchaThe fetch function in Service Workers may not have access to the DOM's fetch API; ensure the polyfill or global fetch is available.
fix
In Service Workers, fetch is available globally; but if not, import a fetch polyfill before using the backend.
affects: >=1.0.0
Errors
Common errors & fixes
Error: fetch is not defined
Running in an environment (e.g., older Node or SSR) without a global fetch implementation.
fix
Install a fetch polyfill like `cross-fetch` or `node-fetch` and assign to global scope before importing i18next-fetch-backend.
TypeError: Failed to parse URL from /locales/en/translation.json
The loadPath expects an absolute URL or a relative path that resolves incorrectly in the current context.
fix
Ensure loadPath starts with '/' or a full URL. Use a function to dynamically construct the path if needed.
Upgrade
Version history
7.0.0latest on npm
Audit
Dependencies
i18nextrequiredPeer dependency required to integrate as a backend plugin.
Agent activity
4 hits · last 30 days
node
4
Resources