@nastilove92

Как решить данную ошибку для запуска бота в дискорде?

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i18next' imported from D:\Анастасия\BotDiskord\bot.js
at packageResolve (node:internal/modules/esm/resolve:854:9)
at moduleResolve (node:internal/modules/esm/resolve:927:18)
at defaultResolve (node:internal/modules/esm/resolve:1169:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
at ModuleWrap. (node:internal/modules/esm/module_job:87:39)
at link (node:internal/modules/esm/module_job:86:36) {
code: 'ERR_MODULE_NOT_FOUND'

The code itself: bot.js
import i18next from 'i18next';
import fsBackend from 'i18next-fs-backend';
import { readFileSync } from 'node:fs';
const { locale } = JSON.parse(readFileSync('./config.json', 'utf-8'));
const fallbackLanguage = 'en';

i18next.use(fsBackend).init({
lng: locale, // if you're using a language detector, do not define the lng option
debug: false,
fallbackLng: fallbackLanguage,
backend: {
loadPath: './Locales/{{lng}}/{{ns}}.json'
}
});

export default {
i18next,
t(key, options) {
let translation = i18next.t(key, options);
if (translation === '') {
// Change language to fallback language, translate the key, then change back to original language
const originalLanguage = i18next.language;
i18next.changeLanguage(fallbackLanguage);
translation = i18next.t(key, options);
i18next.changeLanguage(originalLanguage);
}
return translation;
}
};

i18n.js:
import i18next from 'i18next';
import fsBackend from 'i18next-fs-backend';
import { readFileSync } from 'node:fs';
const { locale } = JSON.parse(readFileSync('./config.json', 'utf-8'));
const fallbackLanguage = 'en';

i18next.use(fsBackend).init({
lng: locale, // if you're using a language detector, do not define the lng option
debug: false,
fallbackLng: fallbackLanguage,
backend: {
loadPath: './Locales/{{lng}}/{{ns}}.json'
}
});

export default {
i18next,
t(key, options) {
let translation = i18next.t(key, options);
if (translation === '') {
// Change language to fallback language, translate the key, then change back to original language
const originalLanguage = i18next.language;
i18next.changeLanguage(fallbackLanguage);
translation = i18next.t(key, options);
i18next.changeLanguage(originalLanguage);

}
return translation;
}
};
  • Вопрос задан
  • 54 просмотра
Пригласить эксперта
Ответы на вопрос 1
Geminix
@Geminix
Фуллстек nuxt, .net разработчик
поставить i18next
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы