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

做~自己de王妃 提交于 2019-12-13 03:24:59

问题


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


回答1:


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.


来源:https://stackoverflow.com/questions/48054005/ng-prod-causes-refresh-on-deploy-after-clicking-the-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!