Dynamic import importing wrong file when using Turbopack
Answered
Spinge Bib Sqorpnts posted this in #help-forum
I am attempting to dynamically import a json file inside a
Snippet:
useEffect
, and it works fine when not using turbopack, but when I add the --turbo
flag, the import statements imports the FIRST file in the directory, instead of the one I need.Snippet:
locale
is a state object that is initialized to he
and is not changed, yet it imports the first file in the translations
dir, which is ar.json
. Hard-coding the path to end with he.json
imports the correct file.import(`../public/assets/translations/${locale}.json`)
.then((msgs) =>
{
console.log(msgs.default); // Checking which file was imported
setMessages(msgs.default);
})
.catch((e) => console.error('Failed to load messages:', e));
4 Replies
I'm using the latest version of next, will attempt next canary in a few moments
Answer
Unfortunately it seems that at least for windows, Turbopack is borked atm: https://github.com/vercel/next.js/issues/63359
yeah turbopack is still quite buggy. my general rule of thumb is that, if you do something and it works in webpack but doesn't work in turbopack, it's turbopack's fault not yours and you are forced to use webpack in that case