Vite: Dynamic import produces duplicate class instance in production
05:32 14 May 2026

In my TypeScript/Vite project inside a module X I‘m doing an dynamic import of that same module by practically* running

import(import.meta.url)

In dev mode this is working as expected, but in production there are being produced multiple instances of X. But my code depends on having a single instance of X, so what can I do?

*) This by itself would be quite dumb; actually one function of X is first exporting a string url=import.meta.url, while another function takes this string as input for calling import().

javascript node.js typescript vite dynamic-import