Angular 10 npm 错误 hasBindingPropertyName 不是函数

Posted

技术标签:

【中文标题】Angular 10 npm 错误 hasBindingPropertyName 不是函数【英文标题】:Angular 10 npm error hasBindingPropertyName is not a function 【发布时间】:2020-12-30 05:22:17 【问题描述】:

我在 Jenkins 构建中突然收到此错误,我尝试升级到最新的 Angular 10.1,但即使升级后问题仍未解决。所以我回滚到 Angular 10.0,下面的 package.json 依赖项

[09/11/2020 03:26:56.420] - 构建:: 编译 @angular/platform-b​​rowser-dynamic/testing : es2015 作为 esm2015 [09/11/2020 03:27:09.120] - 构建:: 错误:工人 #5 错误: TypeError: dir[ioType].hasBindingPropertyName 不是函数 [09/11/2020 03:27:09.120] - 构建:: at Project_folder/node_modules/@angular/compiler/bundles/compiler.umd.js:30061:79 [09/11/2020 03:27:09.120] - Build:: at Array.find () [09/11/2020 03:27:09.120] - 构建:: 在 setAttributeBinding

包.json

"dependencies": 
    "@angular-devkit/build-angular": "0.1000.4",
    "@angular/animations": "^10.0.7",
    "@angular/common": "^10.0.7",
    "@angular/compiler": "^10.0.7",
    "@angular/core": "^10.0.7",
    "@angular/forms": "^10.0.7",
    "@angular/platform-browser": "^10.0.7",
    "@angular/platform-browser-dynamic": "^10.0.7",
    "@angular/router": "^10.0.7",
    "@ng-idle/core": "^8.0.0-beta.4",
    "@ng-idle/keepalive": "^8.0.0-beta.4",
    "@nguniversal/express-engine": "^9.1.1",
    "@nguniversal/module-map-ngfactory-loader": "^8.1.1",
    "async-exit-hook": "^2.0.1",
    "body-parser": "^1.18.3",
    "cfenv": "^1.2.2",
    "classlist.js": "^1.1.20150312",
    "core-js": "^3.0.0",
    "crypto-js": "3.1.9-1",
    "d3": "^5.9.2",
    "dotenv": "^8.1.0",
    "eureka-js-client": "^4.4.2",
    "file-saver": "^2.0.1",
    "google-maps": "^4.3.2",
    "healthcheck-ping": "^2.0.1",
    "hystrixjs": "^0.2.0",
    "jsnlog": "^2.29.0",
    "json-logic-js": "^1.2.2",
    "jsrsasign": "^8.0.20",
    "memory-cache": "^0.2.0",
    "morgan": "^1.9.1",
    "ng2-cookies": "^1.0.12",
    "ng2-slimscroll": "^2.0.1",
    "ngx-ui-loader": "^9.1.1",
    "ngx-webstorage": "^5.0.0",
    "node-fetch": "^2.3.0",
    "preboot": "^7.0.0",
    "reflect-metadata": "^0.1.13",
    "source-map-support": "^0.5.11",
    "string-to-json": "^0.1.0",
    "text-mask-addons": "^3.8.0",
    "tslib": "^2.0.0",
    "web-animations-js": "^2.3.2",
    "weighted-round-robin": "^2.0.2",
    "zone.js": "~0.10.3"
  ,
  "devDependencies": 
    "@angular/cli": "^10.0.4",
    "@angular/compiler-cli": "^10.0.7",
    "@angular/language-service": "^10.0.7",
    "@types/express": "^4.17.7",
    "@types/google-maps": "^3.2.2",
    "@types/jasmine": "^3.5.11",
    "@types/jasminewd2": "^2.0.6",
    "@types/node": "^14.0.23",
    "@types/node-fetch": "^2.5.5",
    "browserstack-local": "^1.3.7",
    "codelyzer": "^6.0.0",
    "cpx": "^1.5.0",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~3.3.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "ng-packagr": "^10.0.0",
    "npm-run-all": "^4.1.5",
    "protractor": "~7.0.0",
    "rimraf": "^3.0.0",
    "ts-loader": "^7.0.5",
    "ts-node": "^8.10.2",
    "tslint": "~6.1.0",
    "typescript": "3.9.7",
    "webpack-bundle-analyzer": "^3.1.0",
    "webpack-cli": "^3.3.12",
    "webpack-node-externals": "^1.7.2"
  

【问题讨论】:

我也遇到了这个问题,你解决了吗? 【参考方案1】:

@angular/compiler 10.1.1 中似乎存在问题。

这不是该问题的解决方案,但我能够通过将 @angular/compiler 和 @angular/compile-cli 降级到 10.0 来解决该问题。仅更新 package.json 是不够的。我还需要清理 node_modules 以恢复代码。

我采取的导致成功构建的步骤...

    更新 package.json
 "dependencies": 
    ...
    "@angular/compiler": "~10.0.3",
    ...
  ,
  "devDependencies": 
    ...
    "@angular/compiler-cli": "~10.0.3",
    ...
  

请注意上面的波浪号 (~) 而不是插入符号 (^),这样 npm 不会自动为您提供 10.1.1。

    rm -rf node_modules

    npm update && ng build --prod

【讨论】:

@JasonAplers 非常感谢您花时间回复这篇文章。效果很好。 版本降级工作完美,但奇怪的是,较新版本的编译器 (10.2.X) 无法解决问题......来自 Angular 团队的任何想法?【参考方案2】:

有时由于 HTML 中的结束标记过多或过少而发生这种情况。 检查您对 html 模板文件的最新更改。

【讨论】:

与 HTML 模板文件无关。问题出在编译器版本上,降级或升级后没有问题 这是我观察到的解决方案之一。可能你的情况不同。感谢您的反馈:)

以上是关于Angular 10 npm 错误 hasBindingPropertyName 不是函数的主要内容,如果未能解决你的问题,请参考以下文章

npm audit fix angular 10.0.1 后的错误

npm 错误!启动Angular前端应用程序时[重复]

错误:npm install -g @angular/cli

Angular2 种子:npm start 有 gulp 错误

npm 错误!缺少脚本:构建:通用

运行 npm -version 时遇到 npm 错误