我现在在运营方面,我对TeamCity构建有问题.

ng build

给出了一些警告

[Run command] Workspace extension with invalid name (defaultProject) found.
[Run command] - Generating browser application bundles (phase: setup)...
[Run command]     TypeScript compiler options "target" and "useDefineForClassFields" are set to "ES2022" and "false" respectively by the Angular CLI. To control ECMA version and features use the Browerslist configuration. For more information, see https://angular.io/guide/build#configuring-browser-compatibility

和错误

[Run command] Error: Can't resolve 'node_modules/chart.js/dist/Chart.js' in '/data/build'

我的Package.json

"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
 "private": true,
  "dependencies": {
    "@angular/animations": "^16.0.0",
    "@angular/cdk": "^16.2.11",
    "@angular/common": "^16.0.0",
    "@angular/compiler": "^16.0.0",
    "@angular/core": "^16.0.0",
    "@angular/forms": "^16.0.0",
    "@angular/platform-browser": "^16.0.0",
    "@angular/platform-browser-dynamic": "^16.0.0",
    "@angular/router": "^16.0.0",
    "@elastic/datemath": "^5.0.3",
    "@once/bootstrap-core": "^2.3.0-20231219134354",
    "chart.js": "^3.9.1",
    "chartjs-adapter-moment": "^1.0.0",
    "chartjs-chart-treemap": "^2.0.2",
    "dayjs": "^1.11.8",
    "flag-icons": "^6.6.6",
    "mobx": "^6.5.0",
    "mobx-angular": "^4.7.2",
    "mobx-utils": "^6.0.8",
    "moment": "^2.29.4",
    "ngx-daterangepicker-material": "^6.0.4",
    "ngx-infinite-scroll": "^16.0.0",
    "primeflex": "^3.2.1",
    "primeicons": "^5.0.0",
    "primeng": "^16.0.0",
    "rxjs": "^7.5.6",
    "tslib": "^2.3.0",
    "web-animations-js": "^2.3.2",
    "zone.js": "^0.13.0"  

我的angular.json

  "architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "../risknews-ui",
        "index": "src/index.html",
        "main": "src/main.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "tsconfig.app.json",
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ],
        "styles": [
          "src/styles.scss"
        ],
        "scripts": [
          "node_modules/chart.js/dist/Chart.js"
        ],
        "allowedCommonJsDependencies": [
          "chart.js"

如何修复此错误?

推荐答案

我认为没有必要导入"node_modules/chart.js/dist/Chart.js",因为你已经导入了,如下所示.

import Chart from 'chart.js';

因此,在angular.json中,我们可以删除该行!("NODE_MODULES/chart.js/dist/Chart.js")

"architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "../risknews-ui",
        "index": "src/index.html",
        "main": "src/main.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "tsconfig.app.json",
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ],
        "styles": [
          "src/styles.scss"
        ],
        "scripts": [], 
        "allowedCommonJsDependencies": [
          "chart.js"

Javascript相关问答推荐

JS、C++和C#给出不同的Base 64 Guid编码结果

确定MutationRecord中removedNodes的索引

过滤对象数组并动态将属性放入新数组

如何从Intl.DateTimeFormat中仅获取时区名称?

使用领域Web SDK的Vite+Vue应用程序中的Web程序集(WASM)错误

闭包是将值复制到内存的另一个位置吗?

以Angular 实现ng-Circle-Progress时出错:模块没有导出的成员

如何在.NET Core中将chtml文件链接到Java脚本文件?

如何利用CSS中的隐藏元素实现平滑扩展和防止网格行间隙

AJAX POST在控制器中返回空(ASP.NET MVC)

MongoDB受困于太多的数据

Google脚本数组映射函数横向输出

我正在试着做一个TicTacToe Ai来和我玩.但是,我试着在第一个方块被点击时出现一个X,然后在第二个方块之后出现一个O

如何使用抽屉屏幕及其子屏幕/组件的上下文?

Reaction即使在重新呈现后也会在方法内部保留局部值

在Puppeteer中使用promise进行日志(log)记录时出现TargetCloseError

如何在Highlihte.js代码区旁边添加行号?

在点击链接后重定向至url之前暂停

MUI-TABLE:MUI表组件中交替行的不同 colored颜色 不起作用

Google OAuth 2.0库和跨域开放程序的问题-策略错误