Angular-cli: ng g component [name] is missing one import after scaffolding

Created on 6 Nov 2017  Â·  4Comments  Â·  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [ x] bug report -> please search issues before submitting
- [ ] feature request

Versions.


``_ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / â–³ \ | '_ \ / _ | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ __| |_|__, |__,_|_|__,_|_| ____|_____|___|
|___/

Angular CLI: 1.5.0
Node: 9.0.0
OS: linux x64
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cdk: 2.0.0-beta.12
@angular/cli: 1.5.0
@angular/material: 2.0.0-beta.12
@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.
<!--
Simple steps to reproduce this bug.
Please include: commands run, packages added, related code changes.
A link to a sample repo would help too.
-->
Create a new component with the command (scaffolding)

ng g component home

### The log given by the failure.
<!-- Normally this include a stack trace and some more information. -->

Date: 2017-11-06T19:54:40.366Z
Hash: 91ab86978ba4c402c781
Time: 6420ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 2.93 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 636 bytes [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 33.6 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 852 kB [initial] [rendered]

ERROR in src/app/home/home.component.ts(7,18): error TS2304: Cannot find name 'ViewEncapsulation'.

webpack: Failed to compile.

### Desired functionality.
<!--
What would like to see implemented?
What is the usecase?
-->

The scaffolding should import in the component ViewEncapsulation:

import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
encapsulation: ViewEncapsulation.None // Here the error
})
export class HomeComponent implements OnInit {

constructor() { }

ngOnInit() {
}
}

```

Mention any other details that might be useful.

The solution that I'm doing right now is add the ViewEncapsulation in the import:

import { Component, OnInit, ViewEncapsulation } from '@angular/core

0 (critical) regression

Most helpful comment

I'm also removing encapsulation: ViewEncapsulation.None from the component. I'd prefer the generator to stop including this (as it was before), rather than including the import.

All 4 comments

I'm able to replicate the issue as well.

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / â–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/

Angular CLI: 1.5.0
Node: 6.10.3
OS: win32 x64
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.5.0
@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
webpack: Compiling...
Date: 2017-11-07T22:38:18.093Z
Hash: 95c0dea77c4c16e0532e
Time: 334ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry]
chunk {main} main.bundle.js (main) 33.8 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 546 kB [initial]
chunk {styles} styles.bundle.js (styles) 539 kB [initial]
chunk {vendor} vendor.bundle.js (vendor) 8.02 MB [initial]

webpack: Compiled successfully.
ERROR in src/app/navbar/navbar.component.ts(7,18): error TS2304: Cannot find name 'ViewEncapsulation'.

I've been removing encapsulation: ViewEncapsulation.None from the component.

I'm also removing encapsulation: ViewEncapsulation.None from the component. I'd prefer the generator to stop including this (as it was before), rather than including the import.

I'm also removing encapsulation: ViewEncapsulation.None from the component. I'd prefer the generator to stop including this (as it was before), rather than including the import.

@kwall2004 I don't know exactly why that was changed, by default Angular uses ViewEncapsulation.Emulated so that makes me think about improve something behind.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings