开发者问题收集

Angular 7 应用程序部署 ng build 无法理解 --target 或 --environment

2019-03-06
2566

我正在将一个 Angular 应用部署到 Netlify。此应用已部署多次,没有出现任何问题。最近,在添加新功能时,我将应用从 Angular 5 升级到 7,并升级了许多依赖项。现在构建失败,信息非常少。

在 Netlify 上,我使用的构建命令是: ng build --target=development --environment=staging 用于开发和 ng build --target=production --environment=prod 用于生产。

Netlify 上的日志是:

3:54:11 PM: Fetching cached dependencies
3:54:11 PM: Starting to download cache of 99.4MB
3:54:12 PM: Finished downloading cache in 773.818516ms
3:54:12 PM: Starting to extract cache
3:54:17 PM: Finished extracting cache in 4.66127562s
3:54:17 PM: Finished fetching cache in 5.479273794s
3:54:17 PM: Starting to prepare the repo for build
3:54:17 PM: Preparing Git Reference pull/102/head
3:54:18 PM: Starting build script
3:54:18 PM: Installing dependencies
3:54:19 PM: Started restoring cached node version
3:54:21 PM: Finished restoring cached node version
3:54:21 PM: v8.15.1 is already installed.
3:54:22 PM: Now using node v8.15.1 (npm v6.4.1)
3:54:23 PM: Attempting ruby version 2.3.6, read from environment
3:54:24 PM: Using ruby version 2.3.6
3:54:24 PM: Using PHP version 5.6
3:54:24 PM: Started restoring cached node modules
3:54:24 PM: Finished restoring cached node modules
3:54:24 PM: Installing NPM modules using NPM version 6.4.1
3:55:17 PM: > [email protected] install /opt/build/repo/node_modules/node-sass
3:55:17 PM: > node scripts/install.js
3:55:17 PM: Downloading binary from https://github.com/sass/node-sass/releases/download/v4.11.0/linux-x64-57_binding.node
3:55:18 PM: Download complete
3:55:18 PM: Binary saved to /opt/build/repo/node_modules/node-sass/vendor/linux-x64-57/binding.node
3:55:18 PM: Caching binary to /opt/buildhome/.npm/node-sass/4.11.0/linux-x64-57_binding.node
3:55:19 PM: > [email protected] postinstall /opt/build/repo/node_modules/node-sass
3:55:19 PM: > node scripts/build.js
3:55:19 PM: Binary found at /opt/build/repo/node_modules/node-sass/vendor/linux-x64-57/binding.node
3:55:19 PM: Testing binary
3:55:19 PM: Binary is fine
3:55:22 PM: npm WARN
3:55:22 PM: optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/webpack-dev-server/node_modules/fsevents):
3:55:22 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
3:55:22 PM: npm WARN optional
3:55:22 PM:  SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
3:55:22 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
3:55:22 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/@angular/compiler-cli/node_modules/fsevents):
3:55:22 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
3:55:22 PM: npm
3:55:22 PM: WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/@angular-devkit/core/node_modules/fsevents):
3:55:22 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
3:55:22 PM: added 561 packages from 247 contributors, removed 635 packages, updated 323 packages and audited 36240 packages in 57.022s
3:55:22 PM: found 0 vulnerabilities
3:55:23 PM: NPM modules installed
3:55:23 PM: Started restoring cached go cache
3:55:23 PM: Finished restoring cached go cache
3:55:23 PM: unset GOOS;
3:55:23 PM: unset GOARCH;
3:55:23 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.10.linux.amd64';
3:55:23 PM: export PATH="/opt/buildhome/.gimme/versions/go1.10.linux.amd64/bin:${PATH}";
3:55:23 PM: go version >&2;
3:55:23 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.10.linux.amd64.env';
3:55:23 PM: go version go1.10 linux/amd64
3:55:23 PM: Installing missing commands
3:55:23 PM: Verify run directory
3:55:23 PM: Executing user command: ng build --target=development --environment=staging
3:55:25 PM: Unknown option: '--target'
3:55:25 PM: Unknown option: '--environment'
3:55:25 PM: Caching artifacts
3:55:25 PM: Started saving node modules
3:55:25 PM: Finished saving node modules
3:55:25 PM: Started saving pip cache
3:55:25 PM: Finished saving pip cache
3:55:25 PM: Started saving emacs cask dependencies
3:55:25 PM: Finished saving emacs cask dependencies
3:55:25 PM: Started saving maven dependencies
3:55:25 PM: Finished saving maven dependencies
3:55:25 PM: Started saving boot dependencies
3:55:25 PM: Finished saving boot dependencies
3:55:25 PM: Started saving go dependencies
3:55:25 PM: Finished saving go dependencies
3:55:25 PM: Error running command: Build script returned non-zero exit code: 1
3:55:25 PM: Failing build: Failed to build site
3:55:29 PM: Finished processing build request in 1m20.618386048s
3:55:30 PM: Shutting down logging, 0 messages pending

我注意到 --target=--environment= 未被处理。在过去的成功部署日志中,这些选项运行良好。因此我假设部署问题与此有关。

有人可以就此提供一些指导吗?

谢谢。

2个回答

查看 文档 中的 ng build 命令,了解最新的 Angular CLI 命令。

缺少这两个选项:

3:55:25 PM: Unknown option: '--target'
3:55:25 PM: Unknown option: '--environment'

对于 --target ,您可以指定 --prod=true

对于 --environment ,您可以指定 --configuration=production (来自 angular.json 文件)

robert
2019-03-06

我相信您可以改用以下参数

对于开发:

--configuration=development
--prod=false

对于生产:

--configuration=production 
--prod=true

您还可以在 此处 阅读有关所有可用参数的信息

Ghonima
2019-03-06