【问题标题】:Getting Unknown option: '-p' while running yarn build:prod Angular 6获取未知选项:运行 yarn build:prod Angular 6 时的“-p”
【发布时间】:2018-06-15 08:21:40
【问题描述】:

我从过去 2 天开始就遇到了这个问题。我已经将 Angular 的版本从版本 4 更新到了 6,但在那之后,我无法创建生产版本。 yarn build、yarn dev 等命令运行良好。但是当我运行 yarn build:prod 时,我收到错误未知选项:'-p'。 我对 Angular 很陌生,无法弄清楚出了什么问题。所以,任何帮助都将不胜感激。

Package.json

    {
  "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

// 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

export const environment = {
  production: true,
  envName: 'prod',
  apiUrl: 'api/v1/',
  publicUrl: 'api/v1/',
  stationUrl: 'dqoz1bwts/',
  bankUrl: 'utils/'
};

angular.json

{
  "$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

yarn build:prod

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

错误截图

tcs --version

tcs 帮助

【问题讨论】:

  • 你能告诉我们你在运行tsc --versiontsc --help时得到了什么吗?
  • 我收到一个错误,我已在问题中更新了相同内容。
  • 好的,检查我更新的答案。

标签: javascript angular yarnpkg angular6


【解决方案1】:

我遇到了同样的错误,看来 Angular 团队改变了命令的工作方式

我以前用过这个:

ng b -prod -e devserver

现在更新的命令是这样的:

ng b --prod --c devserver

观察 -prod 更改为 --prod 并且 -e(或 -environment)更改为 -c(或 -configuration)

希望对你有帮助

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      好的,所以你没有 Typescript..?尝试重新安装它:

      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 吗?)

      【讨论】:

        猜你喜欢
        • 2018-11-21
        • 2021-04-12
        • 2011-09-09
        • 1970-01-01
        • 1970-01-01
        • 2018-10-28
        • 2022-06-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多