Search code examples
angulardeploymentproduction-environment

Ng --prod causes refresh on deploy after clicking the button


My project works perfectly when I run the project via 'Ng Serve or Ng serves --aot', however in production mode (--prod) it happens refresh


Solution

  • Your problem is most likely due to incompatibility between some npm packages. If you use Angular CLI, you should do the following (This is the easiest way I can help based on your provided info):

    • upgrade Angular CLI by running this command in the terminal npm install -g @angular/cli@1.6.2.

    • Next, in your package.json file, ensure that your npm packages have the same versions & semantic versioning i.e. *, ^ or ~ as the ones as follows (I got this by generating a project using Angular CLI 1.6.2):

      Remember to keep any libraries other than the following that you still use!

    "dependencies": {
        "@angular/animations": "^5.0.0",
        "@angular/common": "^5.0.0",
        "@angular/compiler": "^5.0.0",
        "@angular/core": "^5.0.0",
        "@angular/forms": "^5.0.0",
        "@angular/http": "^5.0.0",
        "@angular/platform-browser": "^5.0.0",
        "@angular/platform-browser-dynamic": "^5.0.0",
        "@angular/router": "^5.0.0",
        "core-js": "^2.4.1",
        "rxjs": "^5.5.2",
        "zone.js": "^0.8.14"
      },
      "devDependencies": {
        "@angular/cli": "1.6.2",
        "@angular/compiler-cli": "^5.0.0",
        "@angular/language-service": "^5.0.0",
        "@types/jasmine": "~2.5.53",
        "@types/jasminewd2": "~2.0.2",
        "@types/node": "~6.0.60",
        "codelyzer": "^4.0.1",
        "jasmine-core": "~2.6.2",
        "jasmine-spec-reporter": "~4.1.0",
        "karma": "~1.7.0",
        "karma-chrome-launcher": "~2.1.1",
        "karma-cli": "~1.0.1",
        "karma-coverage-istanbul-reporter": "^1.2.1",
        "karma-jasmine": "~1.1.0",
        "karma-jasmine-html-reporter": "^0.2.2",
        "protractor": "~5.1.2",
        "ts-node": "~3.2.0",
        "tslint": "~5.7.0",
        "typescript": "~2.4.2"
      }
    
    • Then, in your project folder where package.json is located, remove the node_modules folder and run npm install.
    • After the installation has finished, you can try having your project built for production and see if it works.