Angular 构建:无法读取未定义的属性“split”

2023-11-22

刚刚从 ng8 升级到 ng11。 当我运行 ngserve 时它工作正常,但是当我运行 build 进行生产时我收到以下错误:

生成 ES5 包以进行差异加载... 发生未处理的异常:C:\P.....\src\app\9-es2015.dce42a686e45767441f2.js:无法读取未定义的属性“split”

我尝试删除代码以查看导致问题的原因,并在组件中找到以下代码,我将枚举更改为它可以工作的硬编码数字,或者如果删除 console.log。 看来是es2015的问题,改成es5解决了。

import {FormTableData} from '../../../form/service/type/form-table-data';
import {FormFieldTypes} from '../../../form/service/type/form-field-types.enum';

export class FormEditorFormData {

  formData: FormTableData;
  fieldType = FormFieldTypes;
  arr: string[];


  constructor(n: number,s:string) {
    let type = 0;
    const option: string[] = [];
    for (const s of this.arr) {
      if (s != null) {
        switch (type) {
          case FormFieldTypes.checkbox:
            const cap = 'pp';
            option.forEach( (currentValue) => {
              console.log(cap);
            });
            break;
        }
      }
    }
  }
}

表单字段类型:

 export enum FormFieldTypes {
  text = 10,
  checkbox = 20,
  numeric = 30,
  option = 40,
  date = 50,
  combo = 60,
  xiny = 70,
  file = 80,
  picture = 90,
  break = 100,
  textArea = 110,
  actionButton = 998,
  none = 999
}

错误日志:

[error] TypeError: C:\Projects\Venditio\admin-client\src\app\9-es2015.8205fce0935da26db9bb.js: Cannot read property 'split' of undefined
    at NodePath.get (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\path\family.js:185:21)
    at BlockScoping.wrapClosure (C:\Projects\Venditio\admin-client\node_modules\@babel\plugin-transform-block-scoping\lib\index.js:534:29)
    at BlockScoping.run (C:\Projects\Venditio\admin-client\node_modules\@babel\plugin-transform-block-scoping\lib\index.js:360:12)
    at PluginPass.BlockStatement|SwitchStatement|Program (C:\Projects\Venditio\admin-client\node_modules\@babel\plugin-transform-block-scoping\lib\index.js:89:24)
    at newFn (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\visitors.js:175:21)
    at NodePath._call (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\path\context.js:55:20)
    at NodePath.call (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\path\context.js:42:17)
    at NodePath.visit (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\path\context.js:92:31)
    at TraversalContext.visitQueue (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\context.js:116:16)
    at TraversalContext.visitSingle (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\context.js:85:19)
    at TraversalContext.visit (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\context.js:144:19)
    at Function.traverse.node (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\index.js:82:17)
    at NodePath.visit (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\path\context.js:99:18)
    at TraversalContext.visitQueue (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\context.js:116:16)
    at TraversalContext.visitMultiple (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\context.js:80:17)
    at TraversalContext.visit (C:\Projects\Venditio\admin-client\node_modules\@babel\traverse\lib\context.js:142:19)

角度.json:

    {
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "primer": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/primer",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
             ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "primer:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "primer:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "primer:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "primer:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "primer:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "primer"
}

ts配置:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "module": "es2020",
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

包,json:

{
  "name": "primer",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --base-href / --deploy-url /venditio-client/ --prod",
    "build-qa-prod": "node --max_old_space_size=2048  ./node_modules/.bin/ng build --prod --configuration=qa --base-href / --deploy-url /",
    "build-qa": "ng build --configuration=qa --base-href / --deploy-url /venditio-client/ --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~11.2.6",
    "@angular/cdk": "^11.2.5",
    "@angular/common": "~11.2.6",
    "@angular/compiler": "~11.2.6",
    "@angular/core": "~11.2.6",
    "@angular/flex-layout": "^11.0.0-beta.33",
    "@angular/forms": "~11.2.6",
    "@angular/material": "11.2.5",
    "@angular/platform-browser": "~11.2.6",
    "@angular/platform-browser-dynamic": "~11.2.6",
    "@angular/router": "~11.2.6",
    "@asymmetrik/ngx-leaflet": "6.0.1",
    "@fullcalendar/core": "^4.3.1",
    "@ngx-loading-bar/core": "^4.2.0",
    "@ngx-loading-bar/router": "4.2.0",
    "@ngx-translate/core": "11.0.1",
    "@ngx-translate/http-loader": "4.0.0",
    "@swimlane/ngx-datatable": "19.0.0",
    "angular-calendar": "0.27.18",
    "angular-tree-component": "8.4.0",
    "chart.js": "^2.9.4",
    "core-js": "^2.6.12",
    "d3": "5.12.0",
    "font-awesome": "^4.7.0",
    "intl": "1.2.5",
    "leaflet": "1.5.1",
    "moment": "2.24.0",
    "ng-block-ui": "^3.0.2",
    "ng2-charts": "^2.4.2",
    "ng2-dragula": "2.1.1",
    "ng2-file-upload": "1.3.0",
    "ng2-validation": "4.2.0",
    "ngx-material-timepicker": "^5.5.3",
    "ngx-perfect-scrollbar": "8.0.0",
    "ngx-toastr": "^13.2.1",
    "primeflex": "^1.3.0",
    "primeicons": "^2.0.0",
    "primeng": "^11.3.1",
    "quill": "^1.3.7",
    "rxjs": "~6.6.0",
    "screenfull": "5.0.0",
    "sweetalert2": "^10.15.6",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2",
    "rxjs-compat": "^6.6.6"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.1102.5",
    "@angular/cli": "^11.2.5",
    "@angular/compiler-cli": "11.2.6",
    "@angular/language-service": "11.2.6",
    "@types/jasmine": "^3.6.7",
    "@types/jasminewd2": "^2.0.6",
    "@types/node": "^12.20.5",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.2.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-cli": "~2.0.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.0.2"
  }
}

我升级到 angular@13 后刚刚遇到这个问题。我通过更新修复了它"version"angular.json 中的字段来自1 to 2.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Angular 构建:无法读取未定义的属性“split” 的相关文章

  • 在从命令行运行的 NestJS 脚本中使用服务

    我知道如何从命令行运行脚本 使用npm or npx ts node script ts 正如所述here https stackoverflow com questions 60704316 run nestjs script from
  • Typescript 和 Mongoose - “this”在实例方法中不可用

    我目前正在将我的 API 从 JS 转换为 TS 然而 我在猫鼬和打字稿方面遇到了一些困难 具体来说 this在我的实例方法中不可用 My code AccountSchema methods comparePassword async f
  • 如何处理发布到 npm 的 Angular 2 模块中的脚本依赖关系

    我最近向 npm 发布了一个 Angular 2 库 我已在库 package json 文件中列出了所有依赖脚本 当我跑步时npm install my library所有依赖脚本都没有安装 所以 我的问题是如何在安装库时安装依赖脚本 N
  • 从 Angular 2 动态表单的 API 设置值

    我正在尝试开始在 Angular 2 中创建动态表单 并且我正在使用 Angular 食谱中的设置here https angular io docs ts latest cookbook dynamic form html作为我的起点 我
  • Visual Studio 代码断点在使用 TypeScript 的 Node.js 上不起作用

    我尝试了很多解决方案 但没有人适合我 代码执行 但我无法放置断点并调试它 请你帮助我好吗 我尝试过以下 VSCode 配置脚本 type node request launch name Typescript Node JS program
  • 将 SCSS 与使用 angular-cli 创建的 Angular 库结合使用

    我创建了一个角度库项目 我想在其中使用 SCSS 样式 所以我已经配置了 ng config schematics schematics angular component styleext scss 这进入了角度 json file sc
  • Typescript 找不到模块

    我在 Typescript 的一个文件 upload ts 中有一个导出的模块 我无法在没有错误的情况下导入到另一个文件 application ts 中 另外 我无法导入 ExpressJS 这是Upload ts
  • 如何使用 Web 套接字和 Angular CLI 设置代理

    我有一个使用 Angular CLI 构建的简单 Web 应用程序 我希望它使用网络套接字与后端通信 我已经编写了后端 并使用一个简单的 index html 页面进行了测试 服务器可以在套接字上发送和接收该页面 在我的 angular c
  • 角度2中未定义的值

    我正在创建一个应用程序 在其中使用 Ag Grid api 在网页上列出我的数据库内容 Ag grid 有一个预定义的 api 来获取所选行的内容 这是我的代码 export class customer entryComponent pu
  • 从父组件调用的子组件内的 Angular 2 ng2-bootstrap 模式

    很难解释这一点 我有一个简单的 ng2 bootstrap 模式示例 我将其扩展为包含主页的 Boostrap 4 Jumbotron 示例模板 现在 ng2 bootstrap 模式不执行任何操作 我可以看到this childModal
  • 未强制执行 Typescript 抽象类静态方法

    我在 TypeScript 中有这个简单的代码 abstract class Config readonly NAME string readonly TITLE string static CoreInterface gt any cla
  • Angular 8 Native Typescript 无崩溃,访问器简写

    角8 我曾经在打字稿方面用作简短的黑客 object accessor accessor accessor to get object accessor accessor accessor 如果其中一个子级为空 则不会冒抛出错误的风险 根据
  • 如何通过自定义指令动态添加组件

    我想编写一个自定义指令 它将根据 div 内的某些逻辑动态添加组件 我在其中使用了自定义指令 我尝试使用 componentFactoryResolver 和 viewContainerRef createComponent 动态添加组件
  • Angular4 屏蔽输入中的字符而不更改其值

    如何屏蔽输入中除 Angular 4 中最后四个字符之外的所有字符 即显示 而不更改实际值 例如 输入文本框中的数字应类似于 1234 且值应为 7671234 使用指令 Directive selector stringHide expo
  • 在指令中动态添加 *ngIf

    如何动态地将 ngIf 添加到用属性指令修饰的元素 为了一个简单的实验 我尝试了这个 Directive selector lhUserHasRights export class UserHasRightsDirective implem
  • Number.IsNaN() 比 isNaN() 更糟糕吗

    Soooooo isNaNJavaScript 显然被破坏了 比如 isNaN isNaN isNaN true isNaN false isNaN 0 返回 false 当它们看起来都是 不是数字 在 ECMAScript 6 中 草案包
  • 从回调中访问状态

    我在从回调访问组件状态时遇到问题 国家的价值num更改正确 但此类更改对于加载时定义的回调函数不可见 import React useState from react class MyObject callback gt void cons
  • 模板解析:找不到管道

    我收到错误 模板解析错误 找不到管道 amDateFormat 这是我的app module ts import NgModule from angular core import MomentModule from angular2 mo
  • 订阅内循环订阅?

    我目前正在与订阅内的 multiples forEach 订阅作斗争 我正在尝试检索对象列表 然后通过它们的 ID 检索它们的图像 目前我已经这样做了 this appTypeService get pipe map apps AppTyp
  • 使用打字稿的 Angular 6 的黄金布局?

    我在用黄金布局 https golden layout com 与 Angular 6 一起 如下本教程 https npm taobao org package embedded enterprises ng6 golden layout

随机推荐

  • 以编程方式激活飞行模式?

    有谁知道如何在 iPhone OS 2 1 上以编程方式取消 激活飞行模式 使用公共 API 无法执行此操作 这意味着 Apple 不会批准 App Store 上执行此操作的应用程序 当然 无论如何您通常都不应该这样做 我很想听听你想到的
  • 从 android 中的图库获取图像时 android 中出现 java.lang.OutOfMemoryError

    我正在使用代码从图库中挑选一张图片 public void onCreate Bundle savedInstanceState super onCreate savedInstanceState setContentView R layo
  • EF4 Code First - 如何正确映射跨多个表拆分实体

    我正在使用 EF4 CTP5 尝试保留一个 POCO 对象 该对象分为两个表 链接是 ContactID 当我保存联系人时 我希望将核心联系人信息保存在一个表 联系人 中 并将拥有该联系人的用户的链接保存在另一个表 UserToContac
  • MongoException:不允许使用零长度键,您是否使用带双引号的 $ ?

    我正在使用 symfony2 和 mongodb 直到今天 一切正常 但是我创建一个新文档 突然出现此错误 MongoException 不允许使用零长度键 您是否使用带双引号的 dm this gt get doctrine odm mo
  • GitLab 统计问题总数

    我想使用 api 统计我的 gitlab 项目上的所有问题 下面是我正在使用的命令 curl header PRIVATE TOKEN xxxxxxx https gitlab myapp com api v4 groups xx issu
  • 在 Typescript 项目中导入 Matter-js

    我找到了这个文件 https www npmjs com package types matter js 我执行这一行 npm install save types matter js 在根 ts 文件中我收到错误消息 Matter 指的是
  • 如何在 Jasper Report 中组织框架,使它们完美浮动?

    在 Jasper 报告中 我有 4 个框架 下图 它们设置了一些属性 如同一个图像中所示 现在 想法是给定某些参数showBlue and showRed框架BLUE and RED分别显示或隐藏 后续帧 浮动 在前一帧之后 考虑以下顺序
  • unordered_set 非常量迭代器

    出于测试目的 我创建了一些 unordered set 并尝试迭代该集合 该集合拥有自己的类 class Student private int matrNr string name public Student const int mat
  • 使用 React、Redux 和 Axios 处理异步请求?

    我是 React JS 和 Redux 的新手 这让我难以上手 我正在尝试使用 Axios 发出 POST 请求 但无法发出请求 可能是我在容器文件中丢失了一些东西 下面是代码 查看plnkr Update 提交后我收到 redux for
  • 将列表与公共元素合并

    我有一个清单 1 1 7 2 1 10 11 12 211 446 469 3 1 10 11 12 13 4 1 11 12 13 215 5 1 15 16 6 1 15 17 216 225 我想合并具有公共元素的列表切片 并索引已合
  • 红宝石浮点精度

    据我了解 Ruby 1 9 2 浮点数的精度为 15 位十进制数字 因此 我期望舍入浮动x精确到小数点后 15 位等于x 对于此计算 情况并非如此 x 0 33 10 x x round 15 gt false 顺便说一下 四舍五入到 16
  • 在 iOS7 GM 中收到 SSL 错误 - “AddTrust 外部 CA 根”不受信任?

    我的 NSURLConnection 类中突然收到来自 iOS7 GM 的 SSL 错误 我无法访问我的任何 API 或 webView 页面 这是一个严重的紧急情况 有人可以帮我吗 错误如下 NSURLConnection CFURLCo
  • 使用事件侦听器克隆引导元素

    我正在尝试克隆一个具有引导程序提供的数据切换行为的引导程序元素 HTML div class container div
  • 我需要帮助使用 MAT 查找内存泄漏

    我正在使用 MAT 来比较两个堆转储 我每天都会进行一次堆转储 它每天都会增加大约 200 兆 我认为泄漏与 java util zip 有关 因为该表显示的内容 也因为我们最近添加了一个新进程来压缩和解压缩大量文件 见图 此时我打开支配器
  • iPhone 上的 HTTP 直播流媒体服务器

    我正在尝试在 iPhone 上运行 HTTP 实时流媒体服务器 该服务器从摄像头捕获视频流并将其提供给 HTML5 客户端 支持 HTTP 实时流媒体 到目前为止 我已经完成了以下工作 iOS 上的 HTTP Live 流媒体服务器 用 N
  • Ext 4.1.1:添加新记录到Store

    我想在商店初始化后添加记录 I tried 加载数据 加载原始数据 add 但似乎没有任何作用 这是我的jsfiddle http jsfiddle net charlesbourasseau zVvLc 有任何想法吗 你需要设置query
  • novalidate 并出现错误 ora-02299

    有人可以帮我解决这个问题吗 id Name 1 aaa 2 bbb 3 aaa gt alter table arc add CONSTRAINT uk arc UNIQUE NAME novalidate error ora 02299
  • 控制 HTML5 视频中的开始位置和播放时长

    我们有一个视频 长 13 分钟 我们希望使用 HTML5 对其进行控制 我们希望能够让用户控制和选择他们想要播放的视频部分 优选地 该控制将通过2个输入字段进行 他们将在第一个框中输入开始时间 以秒为单位 并在第二个框中输入播放持续时间 以
  • Haxe 在 PHP 环境中部署的 Web“框架”?

    最近我一直在看Haxe 构建要部署到运行 PHP 的 Apache 的应用程序 好吧 虽然它看起来可能适合我的需求 部署到 PHP 但不使用糟糕的语言 但我还没有发现任何东西可以使实际应用程序开发比构建传统的非 MVC PHP 应用程序更容
  • Angular 构建:无法读取未定义的属性“split”

    刚刚从 ng8 升级到 ng11 当我运行 ngserve 时它工作正常 但是当我运行 build 进行生产时我收到以下错误 生成 ES5 包以进行差异加载 发生未处理的异常 C P src app 9 es2015 dce42a686e4