无法在 Safari 中修复:SyntaxError:升级到 Angular 16 后字符无效:“#”

cannot fix in Safari: SyntaxError: Invalid character: '#' after upgrade to Angular 16

提问人:Alin Lazar 提问时间:6/5/2023 最后编辑:Alin Lazar 更新时间:9/12/2023 访问量:457

问:

我升级到了 Angular 16,我已经升级了软件包,但在 Safari 中出现以下错误:SyntaxError:无效字符:“#” 我的 safari 版本是 14。在Chrome中,我没有收到此错误,并且应用程序打开。

查看package.json

{
  "name": "carpathia",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~16.0.4",
    "@angular/cdk": "~16.0.3",
    "@angular/common": "~16.0.4",
    "@angular/compiler": "~16.0.4",
    "@angular/core": "~16.0.4",
    "@angular/forms": "~16.0.4",
    "@angular/localize": "^16.0.4",
    "@angular/material": "^16.0.3",
    "@angular/platform-browser": "~16.0.4",
    "@angular/platform-browser-dynamic": "~16.0.4",
    "@angular/router": "~16.0.4",
    "rxjs": "~7.8.1",
    "stable": "^0.1.8",
    "tslib": "^2.5.3",
    "webpack": "^5.85.0",
    "yarn": "^1.22.19",
    "zone.js": "~0.13.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^16.0.4",
    "@angular/cli": "~16.0.4",
    "@angular/compiler-cli": "~16.0.4",
    "@angular/language-service": "~16.0.4",
    "@types/jasmine": "~4.3.2",
    "@types/jasminewd2": "~2.0.10",
    "@types/node": "^20.2.5",
    "codelyzer": "^6.0.2",
    "jasmine-core": "^4.0.0",
    "jasmine-spec-reporter": "~7.0.0",
    "karma": "~6.4.2",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage-istanbul-reporter": "~3.0.3",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "^2.0.0",
    "protractor": "^7.0.0",
    "terser-webpack-plugin": "^5.3.9",
    "ts-node": "~10.9.1",
    "tslint": "^6.1.3",
    "typescript": ">=4.9.3 and <5.1.0",
    "webpack-cli": "^5.1.2"
  }
}

我尝试降级软件包,更改不同版本的 Webpack,降级和升级 Node 并删除自定义样式,但没有任何效果。当我运行 npx browserslist 时,我看到 Safari 14 不在列表中,并且没有任何工作可以将其列入列表。

Angular Safari 语法错误 无效字符

评论

0赞 dtthom09 6/5/2023
我鼓励您仔细检查版本号是否与 Angular 9 兼容
0赞 Chris Barr 6/5/2023
它说错误来自哪里?如果没有这些信息,很难猜测是什么原因导致了这种情况。您的软件包文件并没有真正提供有关 Safari 中运行时错误的大量信息。

答:

0赞 Anton 7/14/2023 #1

Safari 14 不支持私有方法 https://caniuse.com/mdn-javascript_classes_private_class_methods

所以你需要用 babel 填充或降级回来

0赞 Peter Lönnquist 9/12/2023 #2

我遇到了同样的问题,并使用browserslist解决了它。通过运行“npx browserslist”,确保在browserslist查询中具有safari 14。我从 改为last 2 versionslast 3 major versions