首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >运行yarn build:prod Angular 6时获取未知选项:'-p‘

运行yarn build:prod Angular 6时获取未知选项:'-p‘
EN

Stack Overflow用户
提问于 2018-06-15 16:21:41
回答 3查看 8.5K关注 0票数 2

我在过去的两天里遇到了这个问题。我已经将Angular的版本从版本4更新到了版本6,但在此之后,我无法创建生产版本。像yarn build,yarn dev这样的命令运行得很好。但是当我运行yarn build:prod时,我得到了未知的错误选项:'-p‘。我是Angular的新手,还不能弄清楚哪里出了问题。因此,任何帮助都将不胜感激。

Package.json

代码语言:javascript
复制
    {
  "name": "nitrogen",
  "version": "0.0.1",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "dev": "node --max_old_space_size=8000 ./node_modules/.bin/ng serve --proxy-config proxy.conf.json",
    "serve:prod": "yarn build:prod && hs -p 4200 dist/",
    "build": "ng build",
    "build:dev": "ng build --statsJson",
    "build:prod": "ng build -prod -aot --statsJson -d /admin",
    "test": "ng test",
    "coverage": "ng test --watch false --cc",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "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",
    "@types/underscore": "^1.8.8",
    "angular2-text-mask": "^8.0.5",
    "bootstrap": "^3.3.7",
    "core-js": "^2.5.7",
    "file-saver": "^1.3.8",
    "jquery": "^3.3.1",
    "moment": "^2.22.2",
    "ng2-file-upload": "^1.3.0",
    "ng2-nvd3": "^2.0.0",
    "ngx-bootstrap": "^1.9.3",
    "ngx-cookie": "^1.0.0",
    "ngx-toastr": "^6.3.0",
    "node-sass": "^4.9.0",
    "raven-js": "^3.26.2",
    "rxjs": "^5.5.11",
    "underscore": "^1.9.1",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8",
    "@angular/cli": "^6.0.8",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/file-saver": "^1.3.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "^6.0.112",
    "codelyzer": "~3.2.0",
    "http-server": "^0.10.0",
    "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.4.3",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.0"
  `}
`}

Envirnment.ts

代码语言:javascript
复制
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const environment = {
  production: false,
  envName: 'dev',
  // apiUrl: 'https://sp.ipsator.com:8443/api/v1/',
  // publicUrl: 'https://sp.ipsator.com:8443/api/v1/'
  apiUrl: 'v1/',
  publicUrl: 'v1/',
  stationUrl: 'dqoz1bwts/',
  bankUrl: 'utils/'
};

Environment.prod.ts

代码语言:javascript
复制
export const environment = {
  production: true,
  envName: 'prod',
  apiUrl: 'api/v1/',
  publicUrl: 'api/v1/',
  stationUrl: 'dqoz1bwts/',
  bankUrl: 'utils/'
};

angular.json

代码语言:javascript
复制
{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "nitrogen": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ],
            "styles": [
              "node_modules/ngx-toastr/toastr.css",
              "node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
              "src/assets/styles/styles.scss"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/bootstrap/dist/js/bootstrap.js"
            ]
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "nitrogen:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "nitrogen:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "nitrogen:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/bootstrap/dist/js/bootstrap.js"
            ],
            "styles": [
              "node_modules/ngx-toastr/toastr.css",
              "node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
              "src/assets/styles/styles.scss"
            ],
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "nitrogen-e2e": {
      "root": "",
      "sourceRoot": "e2e",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "nitrogen:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "nitrogen",
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "admin",
      "styleext": "scss"
    },
    "@schematics/angular:directive": {
      "prefix": "admin"
    }
  }
}

Stage.json

代码语言:javascript
复制
yarn build:prod

sed -i '' -e "s|/admin/|http://nitrogen-assets.s3-website.ap-south-1.amazonaws.com/admin/|g" dist/index.html

错误屏幕截图

tcs --版本

tcs帮助

EN

回答 3

Stack Overflow用户

发布于 2018-07-04 03:27:57

我得到了同样的错误,似乎Angular团队改变了命令的工作方式

我以前用过这个:

代码语言:javascript
复制
ng b -prod -e devserver

现在,更新后的命令如下:

代码语言:javascript
复制
ng b --prod --c devserver

注意到-prod更改为--prod和-e (或-environment)更改为-c (或-configuration)

希望能有所帮助

附加信息:https://medium.com/@beeman/how-to-do-x-in-angular-cli-v6-db7530c23066

票数 7
EN

Stack Overflow用户

发布于 2019-02-14 11:34:46

不是tcs --version它应该是tsc --version。尝试使用ng build --prod,如@mahval所说

票数 1
EN

Stack Overflow用户

发布于 2018-06-15 16:30:51

好的,所以你没有打字稿?尝试重新安装它:

  1. $ rm -rf /node_modules
  2. $ npm install -g typescript
  3. $ npm install typescript --save-dev.
  4. $ npm install

或者是Yarn,我猜:

  1. $ rm -rf /node_modules
  2. $ yarn global add typescript
  3. $ yarn add --dev typescript.
  4. $ yarn install

看看这有没有帮助。

(您不是用两个--破折号来编写$ ng build --prod吗?)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50871683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档