remix-i18next: remix-i18next does not provide an export named 'RemixI18Next'
Describe the bug
i dont see any errors in vscode but when starting yarn dev i get these errors:
SyntaxError: The requested module 'remix-i18next' does not provide an export named 'RemixI18Next'
/Users/revnandi/Documents/repos/epick-stack/build/index.js:141
import { RemixI18Next } from "remix-i18next";
SyntaxError: The requested module 'remix-i18next' does not provide an export named 'RemixI18Next'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:122:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:188:5)
at async CustomizedModuleLoader.import (node:internal/modules/esm/loader:246:24)
at <anonymous> (/Users/revnandi/Documents/repos/epick-stack/index.js:20:2)
the i18next.server.ts file:
import Backend from 'i18next-fs-backend'
import { resolve } from 'node:path'
import { RemixI18Next } from 'remix-i18next'
import i18n from './i18n.ts'; // your i18n configuration file
let i18next = new RemixI18Next({
detection: {
supportedLanguages: i18n.supportedLngs,
fallbackLanguage: i18n.fallbackLng,
},
// This is the configuration for i18next used
// when translating messages server-side only
i18next: {
...i18n,
backend: {
loadPath: resolve('./public/locales/{{lng}}/{{ns}}.json'),
},
},
// The i18next plugins you want RemixI18next to use for `i18n.getFixedT` inside loaders and actions.
// E.g. The Backend plugin for loading translations from the file system
// Tip: You could pass `resources` to the `i18next` configuration and avoid a backend here
plugins: [Backend],
});
export default i18next;
Your Example Website or App
wip, based on https://github.com/epicweb-dev/epic-stack
Steps to Reproduce the Bug or Issue
- install package
- add configuration
- yarn dev
Expected behavior
There should not be any error, remix-i18next exports ‘RemixI18Next’
Screenshots or Videos
No response
Platform
OS: macOS Ventura Browser: Chrome Version: remix 1.19.1, remix-i18next: 5.3.0
Additional context
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 8
- Comments: 28 (6 by maintainers)
If you are using a brand new Remix (v2.X) it is now ESM by default and this library doesn’t work well with that right now.
You should add it to your
serverDependenciesToBundle
in yourremix.config.js
file:Or you could convert your whole app back to CJS like @T0mThomson is proposing, but I think it is a bit extreme.
In
package.json
set type tocommonjs
:Edit
remix.config.js
and replace “export default {
” with “module.exports = {
”. Then add the lineserverModuleFormat: "cjs"
.Example:
It is working on 2.0.1 with
I also add to install
intl-parse-accept-language
packageHi, same here. This happend when i migrate my remix project to use v2_dev: true and set my config to use
esm
modules instead. I have just tried to add remix-i18next to serverDependenciesToBundle and it worked just fine!I already made a pull request. You need to update your server-side configuration In your
entry.server.tsx
replace the code with this:Also in
package.json
set type tocommonjs
:And lastly edit
remix.config.js
and replace “export default {
” with “module.exports = {
”. Then add the lineserverModuleFormat: "cjs"
.Example:
This will only work in remix 2.0.0
I’ve figured it out on my own the same way @sergiodxa did, it works.
For those looking for an instant solution:
@eliawk the moduleResolution is only required since v6 because it’s using package.json exports key to define each path (
remix-i18next/server
,remix-i18next/react
andremix-i18next/client
), and TS can’t find them correctly without that setting.@eliawk check if you have moduleResolution set to Bundler, that’s required to TS to find the /react module
In my case, the issue:
Cannot find module 'remix-i18next/server' or its corresponding type declarations.ts(2307)
is gone if I set"moduleResolution": "Bundler"
intsconfig.json
file. Or if you usei18next.server.ts
you should rename it toi18next.server.js
.Ok I just tried a newly created Remix + Vite application and setup remix-i18next without any issue, here’s the archived repo with the app code https://github.com/sergiodxa/remix-vite-i18next for anyone interested.
If your app doesn’t work compare with this app.
Still have the issue with remix@2.0.0.
It’s still broken according to https://publint.dev/remix-i18next@5.4.0.
adding to serverDependenciesToBundle worked, thanks
hi, @revnandi similar issue happened to me just 10mins ago. I use pnpm and the following is the output after the fresh install
I reinstalled remix-i18next with the version “^5.0.0”. It is working now without an issue.