我在过去的两天里遇到了这个问题。我已经将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 --版本
tcs帮助
发布于 2018-07-04 03:27:57
我得到了同样的错误,似乎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
发布于 2019-02-14 11:34:46
不是tcs --version它应该是tsc --version。尝试使用ng build --prod,如@mahval所说
发布于 2018-06-15 16:30:51
好的,所以你没有打字稿?尝试重新安装它:
$ rm -rf /node_modules
$ npm install -g typescript
$ npm install typescript --save-dev
.$ npm install
或者是Yarn,我猜:
$ rm -rf /node_modules
$ yarn global add typescript
$ yarn add --dev typescript
.$ yarn install
看看这有没有帮助。
(您不是用两个--
破折号来编写$ ng build --prod
吗?)
https://stackoverflow.com/questions/50871683
复制相似问题