ng build --prod =无法设置未定义的属性'_autoActivated'

col*_*unk 2 tweenmax angular

我正在尝试部署我的Angular App但在运行后ng build --prod --base-href .我在Chrome中遇到以下错误

main.afc84290417a517dd6c3.js:1 Uncaught TypeError: Cannot set property _autoActivated' of undefined
    at Object.zUnb (main.afc84290417a517dd6c3.js:1)
    at p (runtime.a66f828dca56eeb90e02.js:1)
    at Object.5 (main.afc84290417a517dd6c3.js:1)
    at p (runtime.a66f828dca56eeb90e02.js:1)
    at n (runtime.a66f828dca56eeb90e02.js:1)
    at Array.e [as push] (runtime.a66f828dca56eeb90e02.js:1)
    at main.afc84290417a517dd6c3.js:1
Run Code Online (Sandbox Code Playgroud)

ng -v输出

Angular CLI: 6.0.8
Node: 8.11.2
OS: darwin x64
Angular: 6.0.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Run Code Online (Sandbox Code Playgroud)

我真的不确定怎么去调试这个?运行ng serve应用程序运行正常.

搜索项目唯一的引用_autoActivated是在TweenMax.js中

export const TweenMax = TweenMaxBase;
TweenMax._autoActivated = [TimelineLite, TimelineMax, CSSPlugin, AttrPlugin, BezierPlugin, RoundPropsPlugin, DirectionalRotationPlugin, Back, Elastic, Bounce, RoughEase, SlowMo, SteppedEase, Circ, Expo, Sine, ExpoScaleEase];
Run Code Online (Sandbox Code Playgroud)

应用依赖 -

 "@angular/animations": "^6.0.7",
    "@angular/cdk": "^6.3.1",
    "@angular/common": "^6.0.7",
    "@angular/compiler": "^6.0.7",
    "@angular/core": "^6.0.7",
    "@angular/forms": "^6.0.7",
    "@angular/http": "^6.0.7",
    "@angular/material": "^6.3.1",
    "@angular/platform-browser": "^6.0.7",
    "@angular/platform-browser-dynamic": "^6.0.7",
    "@angular/router": "^6.0.7",
    "@types/three": "^0.92.11",
    "core-js": "^2.5.4",
    "gsap": "^2.0.1",
    "hammerjs": "^2.0.8",
    "normalize-scss": "^7.0.1",
    "normalize.css": "^8.0.0",
    "rxjs": "^6.2.1",
    "three": "^0.87.1",
    "three-effectcomposer-es6": "0.0.4",
    "three-screen-quad": "^0.2.1",
    "zone.js": "^0.8.26"
Run Code Online (Sandbox Code Playgroud)

小智 7

我有同样的问题.您必须添加以下脚本angular.json

"scripts": [
              "./node_modules/gsap/umd/TweenMax.js",
              "./node_modules/gsap/umd/ScrollToPlugin.js"]
Run Code Online (Sandbox Code Playgroud)


小智 6

我遇到了同样的问题,这是由GSAP与Angular的Build Optimizer结合引起的。

您可以通过进入来禁用此功能,但要花一些文件大小angular.json。像这样设置生产构建配置:

"configurations": {
  "production": {
    "optimization": true,
    "outputHashing": "all",
    "sourceMap": false,
    "extractCss": true,
    "namedChunks": false,
    "aot": true,
    "extractLicenses": true,
    "vendorChunk": false,
    "buildOptimizer": false, // <-- This ensures compatibility with GSAP
    "fileReplacements": [
      {
        "replace": "src/environments/environment.ts",
        "with": "src/environments/environment.prod.ts"
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)