0

请理解,由于我的英语不好,可能难以理解。

我们创建了一个新的 Angular 项目,并确认它在与 Safari 连接时工作正常。但问题是我正在做的项目不起作用。

Chrome 的表现非常好,但如果你进入 safari,它只会出现在白屏上。

我目前使用的是 Angular-cli 9.0.7,而 Node 使用的是 10.16.0。

已经进行了许多尝试来解决此问题,但都失败了(更改 base_href、更改 polyfils、检查浏览器列表、更改构建选项等)。

如果您进入 safari,则会出现以下错误。

SyntaxError:意外的关键字“this”。预期一个';' 在返回声明之后。[N] promiseReactionJob

ng serve 和 ng build 都遇到错误。下面是我正在使用的 ng build 命令和 ng serve 命令。

ng build : 'ng build --output-path deploy/public --base-href / --configuration=alpha --aot=true --output-hashing=all'

ng serve : 'ng serve --configuration=local --aot=true --sourceMap=false' 或 'ng serve --configuration=local'

以下是我的项目的设置文件。

包.json

{
  "name": "my-project",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --configuration=local",
    "startAlpha": "ng serve --configuration=alpha --aot=true --sourceMap=false",
    "startProduction": "ng serve --configuration=production --aot=true --sourceMap=false",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~9.0.1",
    "@angular/cdk": "^12.0.5",
    "@angular/common": "~9.0.1",
    "@angular/compiler": "~9.0.1",
    "@angular/core": "~9.0.1",
    "@angular/forms": "~9.0.1",
    "@angular/material": "^9.2.4",
    "@angular/platform-browser": "~9.0.1",
    "@angular/platform-browser-dynamic": "~9.0.1",
    "@angular/router": "~9.0.1",
    "@ngx-translate/core": "^13.0.0",
    "@ngx-translate/http-loader": "^4.0.0",
    "browserslist": "^4.16.6",
    "hammerjs": "^2.0.8",
    "ngx-cookie-service": "^12.0.0",
    "ngx-smart-modal": "^7.4.1",
    "normalize.css": "^8.0.1",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.900.2",
    "@angular/cli": "~9.0.2",
    "@angular/compiler-cli": "~9.0.1",
    "@angular/language-service": "~9.0.1",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "protractor": "~5.4.3",
    "ts-node": "~8.3.0",
    "typescript": "~3.7.5"
  }
}

浏览器列表

browserslist

# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries

# You can see what browsers were selected by your queries by running:
#   npx browserslist

> 0.5%
last 2 versions
Firefox ESR
not dead
not IE <= 10

结果

and_chr 91
and_ff 89
and_qq 10.4
and_uc 12.12
android 91
baidu 7.12
chrome 92
chrome 91
chrome 90
edge 91
edge 90
firefox 90
firefox 89
firefox 78
ie 11
ios_saf 14.5-14.7
ios_saf 14.0-14.4
ios_saf 13.4-13.7
kaios 2.5
op_mini all
op_mob 62
opera 77
opera 76
safari 14.1
safari 14
samsung 14.0
samsung 13.0

polyfils.ts

import 'zone.js/dist/zone';  // Included with Angular CLI.

角.json

angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "my-project": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "crossOrigin": "use-credentials",
            "showCircularDependencies": false,
            "outputPath": "dist/my-project",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/assets/i18n/"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "crossOrigin": "use-credentials",
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "4mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "20kb"
                }
              ]
            },
            "alpha": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.alpha.ts"
                }
              ],
              "crossOrigin": "use-credentials",
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "4mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "20kb"
                }
              ]
            },
            "local": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.local.ts"
                }
              ],
              "crossOrigin": "use-credentials",
              "optimization": false,
              "outputHashing": "none",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "showCircularDependencies": false,
              "aot": true,
              "extractLicenses": false,
              "statsJson": false,
              "progress": false,
              "vendorChunk": true,
              "buildOptimizer": false,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "4mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "20kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "my-project:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "my-project:build:production"
            },
            "alpha": {
              "browserTarget": "my-project:build:alpha"
            },
            "local": {
              "browserTarget": "my-project:build:local"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "my-project:build"
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "my-project:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "my-project:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "my-project",
  "cli": {
    "analytics": false
  }
}

tsconfig.app.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

请救救我。几个小时以来,我一直在寻找那个错误。但我没有适合我的解决方案。

如果你认识任何人,请帮助我。

(更新)我成功地将“web-animations-js”添加到 polyfils,但它没有用。TT

4

1 回答 1

0

我们找到了原因。对 Git Commit 进行一一分析后发现,lookbehind regex 不支持 safari 和 Firefox。

如果其他人有上述错误,请检查您是否使用lookbehind regex。

于 2021-07-26T09:29:00.160 回答