localized-strings
localized-strings copied to clipboard
TypeScript Error
Hi, I'm getting this error on typescript
Error: 'default' is not exported by node_modules/localized-strings/lib/LocalizedStrings.js

How are you importing the module?
I tried like that import LocalizedStrings from 'localized-strings'
I have the same
export default new LocalizedStrings({
^
TypeError: LocalizedStrings is not a constructor
at <anonymous> (/home/daniel/pro/bookcars/api/src/config/app.config.ts:3:16)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
with code
import LocalizedStrings from 'localized-strings';
export default new LocalizedStrings({
fr: {
ERROR: 'Erreur interne : ',
node 18, with tsx
.
I found workaround
const LocalizedStringsConstructor: typeof LocalizedStrings = 'default' in LocalizedStrings ? LocalizedStrings.default as typeof LocalizedStrings : LocalizedStrings;
export default new LocalizedStringsConstructor({
fr: {
ERROR: 'Erreur interne : ',
now it works both with tsx
and jest
with ts-jest
and jest-esbuild
as transformer.