Incompatible with turbopack
Closed this issue · 3 comments
Steps:
git clone https://github.com/i18nexus/next-i18n-router.git && \
cd next-i18n-router/examples/i18next-example/ && \
nvm use 20 && \
npm i && \
sed -i -e 's/next dev/next dev --turbo/g' package.json && \ # switch to using turbopack
sed -i -e 's/@\/locales/..\/locales/g' app/i18n.ts && \ # `@` doesn't resolve correctly with turbopack
npm run dev
Result:
It seems like turbopack is doing some kind of weird static analysis to try and resolve this dynamic import. For some reason the module resolves to an empty object ({}
).
Everything above will work exactly as it should if you remove --turbo
.
Hmm, yeah it appears that Turbopack doesn't work with dynamic imports using "@". After changing to a relative path, it is able to resolve correctly. However, there are still issues.
In the react-intl example, the primary issue is that Turbopack seems to be caching the dynamic import. No matter which language is attempted to be imported, it imports the messages from the first json file in the messages
directory. In our example's case, it always loads de.json
no matter which language file is dynamically imported. I think this issue describes this problem: vercel/next.js#56531
For the react-i18next example, something else strange is going on. There seems an infinite loop that occurs on loading the page. But there are no error messages. I think this issue is described here: vercel/turborepo#5408
In the end, I think this all stems from the fact turbo is still in beta and there are problems that still need to be sorted out, especially with middleware.
I'm gong to close this since this bug is with turbo instead of this library.
Yeah I am loading translations dynamically using resourcesToBackend function with somethign like import ('locales/${language}/${namespace}.json') and it totally fails to import correct language and just imports first file from first language and uses that :D without --turbo it works as expected... turbo is broken :) I fixed it by using static imports, not that nice... but at least it works