1

I have upgraded my angular version from 7 to 14. I have resolved all the errors and compiled successfully on ng serve. but we I try to run app using localhost:4200 I am getting error in browser console that

main.js:1 Uncaught Error: JIT compiler unavailable
    at ls (main.js:1:1922908)
    at Module.w3 (main.js:1:2080648)
    at main.js:1:4540
    at 44226 (main.js:1:4801)
    at r (runtime.js:1:147)
    at 73638 (main.js:1:352642)
    at r (runtime.js:1:147)
    at Ee (main.js:1:2720908)
    at main.js:1:2720929
    at f (runtime.js:1:4115)

Which is most probably due deprecated libraries, I have been asked to resolve this error without replacing some libraries. I am blank in this matter... the project I am working on is way old.

here is my Packages.json file:

{
  "name": "wsi-portal",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "install": "npm run napa",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "modernizr": "modernizr -c modernizr-config.json -d src/modernizr.js",
    "postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points",
    "napa": "napa",
    "ng-high-memory": "node --max_old_space_size=16384 ./node_modules/@angular/cli/bin/ng"
  },
  "browser": {
    "child_process": false
  },
  "private": true,
  "napa": {
    "jquery.flot.spline": "miloszfalinski/jquery.flot.spline",
    "ika.jvectormap": "kakirigi/ika.jvectormap",
    "flot": "flot/flot#v0.8.3"
  },
  "dependencies": {
    "@angular-devkit/build-webpack": "^0.1401.0",
    "@angular/animations": "~14.0.5",
    "@angular/cdk": "^14.0.4",
    "@angular/common": "~14.0.5",
    "@angular/compiler": "~14.0.5",
    "@angular/core": "~14.0.5",
    "@angular/forms": "~14.0.5",
    "@angular/material": "^14.0.4",
    "@angular/platform-browser": "~14.0.5",
    "@angular/platform-browser-dynamic": "~14.0.5",
    "@angular/router": "^14.0.5",
    "@circlon/angular-tree-component": "^11.0.4",
    "@fullcalendar/angular": "^5.11.0",
    "@fullcalendar/bootstrap": "^5.11.0",
    "@fullcalendar/core": "^5.11.0",
    "@fullcalendar/daygrid": "^5.11.0",
    "@fullcalendar/google-calendar": "^5.11.0",
    "@fullcalendar/interaction": "^5.11.0",
    "@fullcalendar/list": "^5.11.0",
    "@fullcalendar/luxon": "^5.11.0",
    "@fullcalendar/moment": "^5.11.0",
    "@fullcalendar/moment-timezone": "^5.11.0",
    "@fullcalendar/rrule": "^5.11.0",
    "@fullcalendar/timegrid": "^5.11.0",
    "@kolkov/angular-editor": "^2.1.0",
    "@ngtools/webpack": "^14.1.0",
    "@ngx-translate/core": "^14.0.0",
    "@ngx-translate/http-loader": "^7.0.0",
    "@pascalhonegger/ng-datatable": "^14.0.0",
    "@types/angular": "^1.8.4",
    "angular-date-value-accessor": "^2.0.1",
    "angular-google-recaptcha": "^1.0.3",
    "angular-mgl-timeline": "^0.4.0",
    "angular2-toaster": "^11.0.1",
    "bootstrap": "^3.3.7",
    "chart.js": "^2.7.1",
    "codemirror": "^5.65.7",
    "css-loader": "^6.7.1",
    "easy-pie-chart": "^2.1.7",
    "font-awesome": "^4.7.0",
    "format-currency": "^1.0.0",
    "fullcalendar": "^5.11.0",
    "html2canvas": "1.0.0-rc.1",
    "https-proxy-agent": "^5.0.1",
    "jquery": "^3.6.0",
    "jquery-slimscroll": "^1.3.8",
    "jquery-sparkline": "^2.4.0",
    "jquery-ui": "^1.12.1",
    "jquery.browser": "^0.1.0",
    "jquery.flot.tooltip": "github:krzysu/flot.tooltip",
    "jspdf-autotable": "^3.1.1",
    "libphonenumber-js": "^1.10.10",
    "loaders.css": "0.1.2",
    "lodash": "^4.17.11",
    "mime": "^2.4.4",
    "mini-css-extract-plugin": "^2.6.1",
    "moment": "^2.24.0",
    "ng-click-outside2": "^11.1.0",
    "ng-multiselect-dropdown": "^0.2.3",
    "ng-pick-datetime": "^7.0.0",
    "ng-select": "^1.0.2",
    "ng2-alt-summernote": "^2.0.0",
    "ng2-charts": "^2.4.2",
    "ng2-ckeditor": "^1.3.3",
    "ng2-daterangepicker": "^3.0.1",
    "ng2-dnd": "^4.2.0",
    "ng2-file-upload": "^1.4.0",
    "ng2-pdf-viewer": "^9.0.0",
    "ng2-pdfjs-viewer": "^13.2.2",
    "ng2-progress-bar": "0.0.8",
    "ng2-select": "^2.0.0",
    "ng2-validation": "^4.1.0",
    "ng4-click-outside": "^1.0.1",
    "ngx-bootstrap": "^8.0.0",
    "ngx-chips": "^1.9.8",
    "ngx-mask": "^14.0.3",
    "ngx-materialize": "^0.0.1",
    "ngx-modialog": "^5.0.1",
    "ngx-progress-bar": "^0.0.10",
    "node-sass": "^7.0.1",
    "npm-check-updates": "^14.1.1",
    "pdfmake": "^0.2.5",
    "popper": "^1.0.1",
    "popsicle-proxy-agent": "^3.0.0",
    "rxjs": "7.5.5",
    "rxjs-compat": "^6.6.7",
    "rxjs-observable": "^0.0.7",
    "screenfull": "^3.3.3",
    "simple-line-icons": "^2.4.1",
    "summernote": "^0.8.11",
    "sweetalert": "^1.1.3",
    "tslib": "^2.4.0",
    "typings": "^2.1.1",
    "web-animations-js": "^2.3.1",
    "zone.js": "~0.11.6"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.0.5",
    "@angular/cli": "^14.0.5",
    "@angular/compiler-cli": "~14.0.5",
    "@angular/language-service": "~14.0.5",
    "@angular/localize": "^14.0.5",
    "@types/googlemaps": "^3.30.20",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/jest": "^28.1.4",
    "@types/jquery": "^3.5.14",
    "@types/lodash": "^4.14.108",
    "@types/mocha": "^9.1.1",
    "@types/node": "^8.10.48",
    "codelyzer": "~4.5.0",
    "core-js": "^3.23.3",
    "husky": "^8.0.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "jspdf": "^1.5.3",
    "karma": "^6.4.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "napa": "^3.0.0",
    "protractor": "~7.0.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~4.7.4"
  }
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    //"allowSyntheticDefaultImports": true,
    "strictPropertyInitialization": false,
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "es2020",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2019",
    "skipLibCheck": true,
    "typeRoots": [
      "node_modules/@types"
    ],
    "types": [ "googlemaps" ],
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "compilationMode": "partial",
    "disableTypeScriptVersionCheck": true,
    "enableI18nLegacyMessageIdFormat": false,
    "enableIvy": true,
    "enableLegacyTemplate": true,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictMetadataEmit": true,
    "strictTemplates": true
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not op_mini all"
  ]

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "wsi-portal": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "architect": {
        "build": {
          //"builder": "@angular-builders/custom-webpack:browser",
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "allowedCommonJsDependencies": [
              "lodash",
              "babel-runtime/helpers"
            ],
            //"customWebpackConfig": {
            //  "path": "./extra-webpack.config.js"
            //},
            "outputPath": "dist/wsi-portal",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",

            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss",
              "src/app/shared/styles/themes/theme-f.scss",
              "node_modules/font-awesome/css/font-awesome.css",
              "node_modules/loaders.css/loaders.css",
              "node_modules/codemirror/lib/codemirror.css",
              "node_modules/summernote/dist/summernote.css",
              "node_modules/sweetalert/dist/sweetalert.css",
              "node_modules/simple-line-icons/css/simple-line-icons.css",
              "node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css",
              "node_modules/@fullcalendar/common/main.css",
              "node_modules/@fullcalendar/daygrid/main.css",
              "node_modules/@fullcalendar/timegrid/main.css",
              "node_modules/@fullcalendar/list/main.css"

            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/jquery/dist/jquery.slim.min.js",
              "node_modules/bootstrap/dist/js/bootstrap.js",
              "node_modules/bootstrap/dist/js/bootstrap.min.js",
              "node_modules/flot/jquery.flot.js",
              "node_modules/jquery.flot.tooltip/js/jquery.flot.tooltip.js",
              "node_modules/flot/jquery.flot.resize.js",
              "node_modules/flot/jquery.flot.pie.js",
              "node_modules/flot/jquery.flot.time.js",
              "node_modules/flot/jquery.flot.categories.js",
              "node_modules/jquery.flot.spline/jquery.flot.spline.js",
              "node_modules/jquery-sparkline/jquery.sparkline.js",
              "node_modules/easy-pie-chart/dist/easypiechart.js",
              "node_modules/chart.js/dist/Chart.bundle.js",
              "node_modules/bootstrap/js/modal.js",
              "node_modules/bootstrap/js/dropdown.js",
              "node_modules/bootstrap/js/tooltip.js",
              "node_modules/summernote/dist/summernote.js",
              "node_modules/sweetalert/dist/sweetalert.min.js",
              "node_modules/jquery-slimscroll/jquery.slimscroll.js"
            ]
            //,"es5BrowserSupport": true
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "30mb",
                  "maximumError": "30mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          //"builder": "@angular-builders/custom-webpack:dev-server",
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "wsi-portal:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "wsi-portal:build:production"
            }
          }
        },
        "extract-i18n": {
          //"builder": "@angular-builders/custom-webpack:extract-i18n",
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "wsi-portal:build"
          }
        },
        "test": {
          "builder": "@angular-builders/custom-webpack:karma",
          //"builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.scss"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          //"builder": "@angular-builders/custom-webpack:tslint",
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "wsi-portal-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "prefix": "",
      "architect": {
        "e2e": {
          //"builder": "@angular-builders/custom-webpack:protractor",
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "wsi-portal:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "wsi-portal:serve:production"
            }
          }
        },
        "lint": {
          //"builder": "@angular-builders/custom-webpack:tslint",
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "wsi-portal"
}
Sana T.
  • 69
  • 1
  • 6
  • 1
    if you do `ng serve --prod` do you also get this error? – Francisco Santorelli Jul 27 '22 at 10:15
  • 1
    If possible can you create stackbliz or share example repo? – Chellappan வ Jul 27 '22 at 10:20
  • 1
    Can [this](https://stackoverflow.com/questions/68798086/jit-compiler-unavailable-after-angular-update) help you? I haven't checked if it's a duplicate, but it seems to be related to your issue. –  Jul 27 '22 at 10:21
  • 2
    `I have been asked to resolve this error without replacing some libraries.` This isn't how updating works, you need to first check if all libraries used are even compatible to Angular 14 before you update. You will have to update and sometimes also replace libraries. –  Jul 27 '22 at 10:23
  • @FranciscoSantorelli I did `ng serve --configuration="production"` it didn't work. Errror status remained same. – Sana T. Jul 27 '22 at 10:36
  • 1
    @MikeS. I replaced libraries which were causing error, now there are just few warnings left. – Sana T. Jul 27 '22 at 10:40
  • 2
    What libraries @SanaT. ? Please complete the answer :( – Narshe Nov 07 '22 at 23:06

1 Answers1

-1

For me, I forgot to import the CommonModule into my shared module file. First time creating a shared module so rookie mistake on my part.

shared-directives.module.ts

import { CommonModule } from '@angular/common'; //this needed to be imported
import { NgModule } from '@angular/core';
import { MyDirective } from './my-directive';

@NgModule({
    imports:[CommonModule], //added CommonModule to imports
    declarations: [
        MyDirective 
    ],

    exports: [
        CommonModule,
        MyDirective
    ]
})
export class SharedDirectivesModule{}

I am not sure if you have to add the CommonModule to exports as I have seen samples with and without. Anyway I found this solution after reviewing this guide on shared modules

Jian Zhen Ng
  • 61
  • 2
  • 6