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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading from v20 to v21 breaks custom backend #1700

Closed
reZach opened this issue Dec 1, 2021 · 3 comments
Closed

Upgrading from v20 to v21 breaks custom backend #1700

reZach opened this issue Dec 1, 2021 · 3 comments

Comments

@reZach
Copy link

reZach commented Dec 1, 2021

馃悰 Bug Report

Upgrading from v20.6.1 to v21.0.0 causes a custom backend to stop working. I reviewed the migration guide and did not see any changes that would imply a custom backend stops working. Roughly, this is the contents of my custom backend

class Backend {
    constructor(services, backendOptions = {}, i18nextOptions = {}) {
        this.init(services, backendOptions, i18nextOptions);   
    }

    init(services, backendOptions, i18nextOptions) {
        // init code
    }

    // Writes a given translation to file
    write(writeQueue) {
        // code
    }

    // Reads a given translation file
    requestFileRead(filename, callback) {
        // code
    }

    // Reads a given translation file
    read(language, namespace, callback) {
        // code
    }

    // Not implementing at this time
    readMulti(languages, namespaces, callback) {
        throw "Not implemented exception.";
    }

    // Writes a missing translation to file
    create(languages, namespace, key, fallbackValue, callback) {
        // code
    }
}
Backend.type = "backend";

export default Backend;

To Reproduce

git clone https://github.com/reZach/secure-electron-template.git
cd secure-electron-template
// change i18next dependency in package.json from ^20.6.1 to ^21.0.0
npm i
npm run dev

Expected behavior

I expect the following error will not be thrown; "Uncaught TypeError: Cannot read property 'use' of undefined"

image

Your Environment

  • runtime version: node v16.13.0, electron v13.6.2
  • i18next version: 21.0.0 (20.6.1 does not have this issue)
  • os: Windows
@jamuhl
Copy link
Member

jamuhl commented Dec 1, 2021

'Cannot read property "use" of undefined' -> looks more like i18n is undefined -> check the import (might be const i18n = require("i18next");)

@adrai
Copy link
Member

adrai commented Dec 1, 2021

I don't know why you used .default, but this fixes it:
image

btw: whitelist does not exist anymore:
image
https://www.i18next.com/misc/migration-guide#removed-deprecated
image

@adrai adrai closed this as completed Dec 1, 2021
@reZach
Copy link
Author

reZach commented Dec 2, 2021

Thanks @adrai / @jamuhl, I'll apply these changes!

adrai added a commit that referenced this issue Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants