Angular 8 没有使用 ng2-adsense 构建

Angular 8 not building with ng2-adsense

我正在为 Angular 个应用程序使用 Google Adsense 库 ng2-adsense 来展示我的广告。

我按照此处找到的步骤操作:https://github.com/scttcper/ng2-adsense/

  1. adsbygoogle.js脚本添加到头部。
  2. AdsenseModule 添加到 NgModule 导入数组。
  3. <ng-adsense> 标记添加到我的 app.component.html 文件中我希望展示广告的位置。

它在本地工作正常(当我运行 ng run serve时没有显示严重错误)。

当我尝试构建我的 angular 应用程序以分发到 Firebase 时,出现以下错误。

ng build --prod

ERROR in ./node_modules/ng2-adsense/fesm5/ng2-adsense.js
Module build failed (from ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js):
TypeError: Cannot read property 'kind' of undefined
    at isAngularDecoratorMetadataExpression (/Users/.../node_modules/@angular-devkit/build-optimizer/src/transforms/scrub-file.js:265:35)

不是永久解决方案,但我通过将 angular.json 文件中的 buildOptimizer 更改为 false 临时修复了生产版本。

                "configurations": {
                        "production": {
                            "optimization": true,
                            "outputHashing": "all",
                            "sourceMap": false,
                            "extractCss": true,
                            "namedChunks": false,
                            "aot": true,
                            "extractLicenses": true,
                            "vendorChunk": false,
                            "buildOptimizer": false,
                            "fileReplacements": [
                                {
                                    "replace": "src/environments/environment.ts",
                                    "with": "src/environments/environment.prod.ts"
                                }
                            ],
                            "budgets": [
                                {
                                    "type": "initial",
                                    "maximumWarning": "2mb",
                                    "maximumError": "5mb"
                                }
                            ]
                        }
                    }
                },