angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng g component [name] is missing one import after scaffolding

Open WilfredoRPL opened this issue 9 years ago • 4 comments

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.

Create a new component with the command (scaffolding)

ng g component home

The log given by the failure.

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.

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

WilfredoRPL avatar Nov 06 '17 20:11 WilfredoRPL

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.

mckalexee avatar Nov 07 '17 22:11 mckalexee

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 avatar Nov 08 '17 01:11 kwall2004

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.

WilfredoRPL avatar Nov 08 '17 12:11 WilfredoRPL

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.