localized-strings icon indicating copy to clipboard operation
localized-strings copied to clipboard

TypeScript Error

Open nbaybara opened this issue 2 years ago • 4 comments

Hi, I'm getting this error on typescript

Error: 'default' is not exported by node_modules/localized-strings/lib/LocalizedStrings.js

Screen Shot 2022-04-07 at 11 57 30

nbaybara avatar Apr 07 '22 08:04 nbaybara

How are you importing the module?

stefalda avatar Apr 07 '22 09:04 stefalda

I tried like that import LocalizedStrings from 'localized-strings'

nbaybara avatar Apr 20 '22 22:04 nbaybara

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.

gustawdaniel avatar May 27 '23 03:05 gustawdaniel

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.

gustawdaniel avatar May 27 '23 04:05 gustawdaniel