Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with dev configuration #2

Open
steosoft opened this issue Apr 19, 2019 · 7 comments
Open

Not working with dev configuration #2

steosoft opened this issue Apr 19, 2019 · 7 comments

Comments

@steosoft
Copy link

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
@aigoncharov
Copy link
Owner

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

@steosoft
Copy link
Author

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"
    }
  }
}

@aigoncharov
Copy link
Owner

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?

@steosoft
Copy link
Author

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?

@aigoncharov
Copy link
Owner

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?

@steosoft
Copy link
Author

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

@aigoncharov
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants