Ng --prod单击按钮后会导致部署刷新 [英] Ng --prod causes refresh on deploy after clicking the button

查看:72
本文介绍了Ng --prod单击按钮后会导致部署刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过 NG服务或Ng服务--aot运行项目时,我的项目可以完美运行,但是在生产模式(--prod)中会刷新

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

推荐答案

您的问题很可能是由于某些npm软件包之间的不兼容所致。如果使用Angular CLI,则应执行以下操作(这是我可以根据您提供的信息提供帮助的最简单方法):

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):


  • 升级Angular通过在终端 npm install -g @ angular / cli @ 1.6.2 中运行此命令来创建CLI。

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

接下来,在您的 package.json 文件中,确保您的npm软件包具有相同的版本&语义版本控制,例如 * ^ 如下所示(我是通过使用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"
  }



  • 然后,在项目文件夹中,其中找到package.json ,删除 node_modules 文件夹,然后运行 npm install

  • 安装完成后,您可以尝试将项目构建为生产环境并查看其是否有效。

    • 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.
    • 这篇关于Ng --prod单击按钮后会导致部署刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆