angular-cli: Angular 5: uncaught ReferenceError: ViewEncapsulation is not defined
Bug Report
- [ x ] bug report -> please search issues before submitting
- [ ] feature request
Versions.
Angular CLI: 1.5.0
Node: 6.11.5
OS: darwin x64
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cdk: 5.0.0-rc0
@angular/cli: 1.5.0
@angular/material: 5.0.0-rc0
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.1
typescript: 2.4.2
webpack: 3.8.1
Repro steps.
ng generate component header
TS code:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.css'],
encapsulation: ViewEncapsulation.None
})
export class HeaderComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
The log given by the failure.
header.component.ts:7 Uncaught ReferenceError: ViewEncapsulation is not defined
at eval (header.component.ts:7)
at eval (header.component.ts:16)
at Object.../../../../../src/app/header/header.component.ts (main.bundle.js:58)
at __webpack_require__ (inline.bundle.js:55)
at eval (app.module.ts:5)
at Object.../../../../../src/app/app.module.ts (main.bundle.js:36)
at __webpack_require__ (inline.bundle.js:55)
at eval (main.ts:4)
at Object.../../../../../src/main.ts (main.bundle.js:74)
at __webpack_require__ (inline.bundle.js:55)
Desired functionality.
Fails to render in browser with console error
Mention any other details that might be useful.
Mac OS
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 15
- Comments: 22 (1 by maintainers)
Commits related to this issue
- 添加新component, fix: https://github.com/angular/angular-cli/issues/8386 — committed to program-in-chinese/angular_official_tutorial_zh by testacount1 7 years ago
This is the official solution: https://angular.io/api/core/ViewEncapsulation
npm Package | @angular/core import { ViewEncapsulation } from ‘@angular/core’;
Looks like the ViewEncapsulation are now imported after upgrading to Angular 5.0.1.
I would also thank the Angular team which are working really hard on this amazing product! And please people, who complains… Stop doing it. You are not paying for this products, so if there are any bugs, instead of complaining, you should try to help to fix the bugs! 😉
I am curious, but, why the components are created with
ViewEncapsulation.Noneinstead ofViewEncapsulation.Emulated?Instead of doing it manually though you can update the
angular.cli.jsonfile using the example below, and you can find it in the wikiSeems the issue could be easily solved to be the Angular default by:
angular.cli.jsonfile should be set to this by default requiring no extra metadata to be added to components. The style guide seems to always suggest not including metadata unless needed for example use@Inputinstead of the metadatainputso keeping this in configuration seems cleaner, orViewEncapsulation.Emulatedand have theViewEncapsulationimported so maintains Angular’s default from v2 and v4Manually removing
encapsulation: ViewEncapsulation.Nonefrom components helped me resolve this issue