Module x can only be default-imported using the allowSyntheticDefaultImports flag

Discussão em 'Angular' iniciado por D_Sunny, Março 24, 2025.

  1. D_Sunny

    D_Sunny Guest

    I am updating from angular 17 to angular 19 using update guide https://angular.dev/update-guide?v=17.0-19.0&l=3

    After updating from v18 to v19 and changing

    import * as moment from 'moment' to import moment from 'moment' and

    import * as SockJS from 'sockjs-client' to import SockJS from 'sockjs-client'

    i am getting errors from Moment.js and sockjs-client: Module can only be default-imported using the allowSyntheticDefaultImports flag

    tsconfig.json:

    {
    "compileOnSave": false,
    "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "experimentalDecorators": true,
    "module": "es2020",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "ES2022",
    "typeRoots": [
    "node_modules/@types"
    ],
    "lib": [
    "es2018",
    "dom"
    ],
    "useDefineForClassFields": false
    },
    "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
    }
    }


    I tried to use es2022 in 'module' and 'target', changed es2018 -> esnext in 'libs', cleared cache (intellij) but nothing helps. I am still facing the compile error. How to fix it?

    Continue reading...

Compartilhe esta Página