i’ve been debugging a problem i have had with a tool that translates my website content for a while now and i’ve narrowed down the problem to a dynamic import that is clearly reading the wrong file.
Basically i have all my original content in an exported object written in dutch located at ./translations/nl/[file].ts
At the first pass it reads all the files correctly from the nl
directory using a dynamic import, in this case translating to french first. After that is done it moves on to the next language, but this time when importing the content (still from the nl
directory, printing the filepath confirms this) it returns the contents of ./translations/fr/[file].ts
i have put a readFileSync()
call with the exact same path after the dynamic import, which does return the correct content. Now this could be fixed easily by using the content read from the readFile call, but there isn’t (atleast that i know of) a way to parse a typescript object on the fly without using await import()
I am using ts-node
to run this tool, this might be responsible for my problems. but when trying an alternative such as esno or tsc, i get the exact same result.
Converting all my localisation files to JSON would probably remedy this, but would also remove all type safety when using these translations in the front-end. So ideally i wouldn’t have to resort to this.
Is this some weird caching problem? and is there any way to avoid using dynamic imports and/or go about this a different way?
Thanks in advance!
2
Answers
I have opted to convert everything to JSON and parse it that way. After the fact adding back an export statement and writing it back to a Typescript file. This seems to be the best solution for now.
This problem has occurred because you are passed props ill-formatted, try changing the props and it would work for you.