The idiomatic singleton is a module export: export const config = createConfig();. Every importer gets the same object because a module body runs once. A class with a static field and a lazy getter works too, but JavaScript can't make a constructor private, so new still makes a second instance.
The catch is what "once" covers. ECMAScript only requires a host to return the same Module Record for the same referrer and request; hosts build on that by caching per resolved URL or path:
- Node.js caches CommonJS by resolved filename and ES modules by URL. Two copies of a package in different
node_modulesfolders are two files, so two instances. A different query string is a different URL, so another instance too. A package that ships separate CommonJS and ESM files can be loaded once byrequireand once byimport. - Bundles. Two bundles (micro-frontends, a library bundled into each consumer) that each include the module each carry their own copy.
- Realms and workers. In HTML, each window, iframe and worker has its own module map; a Node.js worker thread loads its own copy of every module.
When copies are a real risk, libraries sometimes store the instance under a Symbol.for key on globalThis. That is shared across copies within one realm, but still not across workers.
When it's a mistake is mostly about state. A singleton is a global variable with an import statement: any module can change it, tests that touch it leak into each other, and you can't substitute a fake without module mocking. A stateless logger or one connection pool per process is a reasonable singleton; mutable app state usually isn't. My default, a judgement call: create the instance once at the entry point and pass it to whoever needs it.