kim93
kim93

Reputation: 41

Uncaught SyntaxError: Cannot use import statement outside a module - Angular 15

I am using angular 15, where on console I am seeing this error of Uncaught SyntaxError: Cannot use import statement outside a module (at scripts.js:7:1) This is my tsconfig.json file code

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": false,
    "noImplicitReturns": false,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "ES2022",
    "module": "ES2022",
    "useDefineForClassFields": false,
    "lib": [
      "ES2022",
      "dom"
    ],
    "paths": {
      "@core/*": [ "src/app/core/*" ],
      "@shared/*": [ "src/app/shared/*" ],
      "@environments/*": [ "src/environments/*"],
  }
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  }
}

package.json -

{
  "name": "test",
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^15.0.0",
    "@angular/cdk": "^15.0.3",
    "@angular/common": "^15.0.0",
    "@angular/compiler": "^15.0.0",
    "@angular/core": "^15.0.0",
    "@angular/forms": "^15.0.0",
    "@angular/platform-browser": "^15.0.0",
    "@angular/platform-browser-dynamic": "^15.0.0",
    "@angular/router": "^15.0.0",
    "chart.js": "^4.2.0",
    "primeflex": "^3.3.0",
    "primeicons": "^6.0.1",
    "primeng": "^15.0.0-rc.1",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.12.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^15.0.1",
    "@angular/cli": "~15.0.1",
    "@angular/compiler-cli": "^15.0.0",
    "@types/jasmine": "~4.3.0",
    "autoprefixer": "^10.4.13",
    "jasmine-core": "~4.5.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "postcss": "^8.4.19",
    "tailwindcss": "^3.2.4",
    "typescript": "~4.8.2"
  }
}

node version - v18.12.1 npm version - 8.19.2

enter image description here

please help me to reach a working solution.

I have tried - 1- add "type": "module" in package.json - not working 2- tsconfig.json added "target": "esnext","module": "commonjs", - not working 3- npm i ts-node --save-dev - not working

Upvotes: 2

Views: 571

Answers (1)

moral
moral

Reputation: 81

I had the same issue and in my case I downgraded chart.js version to 3.3.2 (the lowest required by primeng).

Upvotes: 0

Related Questions