Search code examples
nativescript

A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference


Just upgrade Nativescript to version 7 and getting the errors below, not sure why nativescript is throwing this error.

This is my package.json:

"dependencies": {
    "@angular/animations": "^10.2.4",
    "@angular/common": "^10.2.4",
    "@angular/compiler": "^10.2.4",
    "@angular/core": "^10.2.4",
    "@angular/forms": "^10.2.4",
    "@angular/platform-browser": "^10.2.4",
    "@angular/platform-browser-dynamic": "^10.2.4",
    "@angular/router": "^10.2.4",
    "@nativescript/angular": "^10.1.7",
    "@nativescript/core": "^7.1.0",
    "@nativescript/webpack": "^4.0.0",
    "@nstudio/nativescript-cardview": "^2.0.1",
    "@types/jest": "^24.0.18",
    "base-64": "^0.1.0",
    "js-base64": "^2.5.2",
    "nativescript-admob": "^4.0.0",
    "nativescript-clipboard": "^2.0.0",
    "nativescript-drop-down": "^5.0.6",
    "nativescript-pdf-view": "^2.4.3",
    "nativescript-permissions": "^1.3.11",
    "nativescript-plugin-firebase": "^10.6.3",
    "nativescript-theme-core": "^1.0.6",
    "nativescript-toast": "^2.0.0",
    "nativescript-ui-calendar": "^7.0.2",
    "nativescript-ui-listview": "^9.0.4",
    "nativescript-ui-sidedrawer": "^9.0.3",
    "reflect-metadata": "~0.1.12",
    "rxjs": "^6.4.0",
    "zone.js": "^0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/schematics": "^10.2.1",
    "@angular/cli": "^10.2.1",
    "@angular/compiler-cli": "^10.2.4",
    "@nativescript/android": "7.0.1",
    "@nativescript/schematics": "^10.1.0",
    "@nativescript/types": "^7.0.4",
    "@ngtools/webpack": "^10.2.1",
    "@schematics/angular": "^10.2.1",
    "@schematics/update": "^0.11.4",
    "node-sass": "^4.13.1",
    "typescript": "^3.9.7"
  },

I also tried typescript 4 but that yields more errors.

Anyone come across this issue below:

enter image description here


Solution

  • Make sure your tsconfig.json contains

    "skipLibCheck": true
    

    it appears to be coming in by default if you're generating a new project but is not being added during update process. Adding it fixed the issue for me and now I'm able to compile the app with no issues.

    Below is an example of my tsconfig file:

    {
      "compilerOptions": {
        "module": "esnext",
        "target": "es2017",
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "noEmitHelpers": true,
        "noEmitOnError": true,
        "skipLibCheck": true,
        "resolveJsonModule": true,
        "esModuleInterop": true,
        "lib": [
          "es2017",
          "dom"
        ],
        "baseUrl": ".",
        "paths": {
          "~/*": [
            "src/*"
          ]
        }
      },
      "exclude": [
        "node_modules",
        "platforms"
      ]
    }