angular-builder-custom-terser-options icon indicating copy to clipboard operation
angular-builder-custom-terser-options copied to clipboard

Not working with dev configuration

Open steosoft opened this issue 5 years ago • 7 comments

After adding angular-builder-custom-terser-options to project ng build --prod and ng serve --prod works very well but when I build ng build or run ng serve dev configuration then I have error in js console when I click anywhere:

ERROR TypeError: Cannot read property 'init' of undefined
    at DefaultStyleDirective.init (core.js:422)
    at new StyleDirective (extended.js:560)
    at new DefaultStyleDirective (extended.js:649)
    at createClass (core.js:28360)
    at createDirectiveInstance (core.js:28186)
    at createViewNodes (core.js:29804)
    at callViewAction (core.js:30254)
    at execComponentViewsAction (core.js:30159)
    at createViewNodes (core.js:29833)
    at createRootView (core.js:29676)
View_DataListComponent_0 @ DataListComponent.html:1
proxyClass @ compiler.js:17198
logError @ core.js:31083
handleError @ core.js:19918
dispatchEvent @ core.js:25918
(anonymous) @ core.js:26581
(anonymous) @ platform-browser.js:1678
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:423
onInvokeTask @ core.js:21826
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:422
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:195
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:498
invokeTask @ zone.js:1744
globalZoneAwareCallback @ zone.js:1770

steosoft avatar Apr 19 '19 12:04 steosoft

What version of angular and angular devtools are you using? Please provide your package.json, package-lock.json and angular.json.

aigoncharov avatar Apr 19 '19 16:04 aigoncharov

package.json:

{
  "name": "xxxxx",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.2.4",
    "@angular/cdk": "^7.3.1",
    "@angular/common": "^7.2.4",
    "@angular/compiler": "^7.2.4",
    "@angular/core": "^7.2.4",
    "@angular/flex-layout": "^7.0.0-beta.23",
    "@angular/forms": "^7.2.4",
    "@angular/http": "^7.2.4",
    "@angular/material": "^7.3.1",
    "@angular/platform-browser": "^7.2.4",
    "@angular/platform-browser-dynamic": "^7.2.4",
    "@angular/platform-server": "^7.2.4",
    "@angular/router": "^7.2.4",
    "@asymmetrik/ngx-leaflet": "^4.0.0",
    "@ngtools/webpack": "^7.3.0",
    "@types/node": "^10.12.21",
    "angular-resizable-element": "^3.2.3",
    "angular2-draggable": "^1.4.2",
    "circular-json": "^0.5.4",
    "core-js": "^2.6.3",
    "hammerjs": "^2.0.8",
    "jquery": "^3.3.1",
    "keycloak-angular": "^6.0.0",
    "leaflet": "^1.4.0",
    "lodash": "^4.17.10",
    "ng2-dragula": "^1.5.0",
    "rxjs": "^6.4.0",
    "ts-md5": "^1.2.4",
    "typings": "^2.1.1",
    "zone.js": "^0.8.29"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.13.0",
    "@angular/cli": "^7.3.0",
    "@angular/compiler-cli": "^7.2.4",
    "@angular/language-service": "^7.2.4",
    "@types/jasmine": "^2.8.16",
    "@types/jasminewd2": "~2.0.2",
    "@types/leaflet": "^1.4.1",
    "angular-builder-custom-terser-options": "^1.0.1",
    "codelyzer": "^4.3.0",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^2.0.2",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.4.2",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "3.2.4",
    "webpack": "^4.29.1"
  }
}

angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "xxxxx": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "angular-builder-custom-terser-options:browser-custom-terser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              {
                "glob": "**/*",
                "input": "node_modules/leaflet/dist/images",
                "output": "/leaflet"
              },
              "src/assets",
              "src/favicon.ico"
            ],
            "styles": [
              "src/styles.css",
              "node_modules/leaflet/dist/leaflet.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js"
            ]
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "terserOptions": {
                "keep_classnames": ".*Component",
                "keep_fnames": ".*Component"
              }
            }
          }
        },
        "serve": {
          "builder": "angular-builder-custom-terser-options:dev-server-custom-terser",
          "options": {
            "browserTarget": "xxxxx:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "xxxxx:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "xxxxx:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js"
            ],
            "styles": [
              "src/styles.css",
              "node_modules/leaflet/dist/leaflet.css"
            ],
            "assets": [
              {
                "glob": "**/*",
                "input": "node_modules/leaflet/dist/images",
                "output": "/leaflet"
              },
              "src/assets",
              "src/favicon.ico"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "xxxxx-e2e": {
      "root": "",
      "sourceRoot": "",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "xxxxx:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "xxxxx",
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "styleext": "css"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  }
}

steosoft avatar Apr 20 '19 14:04 steosoft

I tried to come up with a demo to reproduce your case, but it works for me. Take a look.

Could you provide a repo or stackblitz demo with a minimal reproduction of your issue?

aigoncharov avatar Apr 23 '19 12:04 aigoncharov

I took a closer look at the issue and if I create new configuration (let's call it "debug") and set only one flag "aot": true then it works fine

          "configurations": {
            "debug": {
              "aot": true
            },
            "production": {
              [...]
            }
          }

ng serve --configuration=debug = everything works correct, no exceptions in console

Any idea what is going on there?

steosoft avatar May 27 '19 12:05 steosoft

Based on your error message it seems like DefaultStyleDirective is not injected in non-aot mode. I had a weird problem related to missing services when I used barrel files. Do you use barrels?

aigoncharov avatar May 27 '19 15:05 aigoncharov

I have checked the code but I don't see there any barrel files.

steosoft avatar May 27 '19 21:05 steosoft

@steosoft could try to come with a repo with a minimal setup to reproduce the issue?

aigoncharov avatar Jun 04 '19 09:06 aigoncharov