Angular CLI dependencies - why do I need to install @angular/router if I don't use it?

Yuriy K.

When I start a blank Angular CLI project, these dependencies from package.json look like not necessary, so I'm trying to remove them (as well as removing FormModules and HttpModules from imports):

@angular/forms": "^4.0.0",
@angular/http": "^4.0.0",
@angular/router": "^4.0.0",

But when I try build the project, I'm getting an error:

'ERROR in Could not resolve module @angular/router'

And what looks even more weird to me, after re-saving a file the project rebuilds successfully and it works.

Can somebody explain where is this hidden dependency from @angular/router?

My files:

app.modules.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';    
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

app.component.ts:

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

@Component({
  selector: 'app-root',
  template: '<h1>test</h1>'
})
export class AppComponent {}
yurzui

Angular cli uses @ngtool/webpack plugin that uses private API from @angular/compiler-cli to get lazy loaded routes

plugin.ts

const {__NGTOOLS_PRIVATE_API_2} = require('@angular/compiler-cli');

https://github.com/angular/angular-cli/blob/v1.0.1/packages/%40ngtools/webpack/src/plugin.ts#L7

// We need to run the `listLazyRoutes` the first time because it also navigates libraries
// and other things that we might miss using the findLazyRoutesInAst.
let discoveredLazyRoutes: LazyRouteMap = this.firstRun ?
__NGTOOLS_PRIVATE_API_2.listLazyRoutes({
  program: this._program,
  host: this._compilerHost,
  angularCompilerOptions: this._angularCompilerOptions,
  entryModule: this._entryModule
})
: this._findLazyRoutesInAst();

https://github.com/angular/angular-cli/blob/v1.0.1/packages/%40ngtools/webpack/src/plugin.ts#L492-L501

Notice this.firstRun.That's why you are getting the error on the first run.

@angular/compiler-cli/src/ngtools_impl.ts

const ROUTER_MODULE_PATH = '@angular/router';

https://github.com/angular/angular/blob/4.1.0/packages/compiler-cli/src/ngtools_impl.ts#L20

Here is reproduction

enter image description here

See also

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

If the file is executable, why do I need to install some dependencies?

Why do I need import React statement even if I don't use React explicitly?

Why don't I need to install any Drivers for Ubuntu

Why is Windows Update trying to install an update I don't need?

Why do I need the keyword TABLE in this dynamic query although I don't need in a normal query

why should I sometimes don't need to use 'get' while othertimes need to use 'get' for filtering?

do i need to install angular if i've installed angula-cli (globally)

Is Next Bad to Use if I Don't Need it?

Why do I need to use angular.copy in my factory?

Why do I need to add "[0]" to my data to get it to render, if I don't, there is an error?

Why will yarn install dev dependencies when I just need the builds?

Why after installing Android Studio on Windows 10 I don't need to install JDK? Is it already there?

Angular 8 do I need to subscribe to a request if I don't care about the response

I couldn't install @angular/cli on ubuntu

When do I need to use an executor for async code? What happens when I don't (but should)?

Do I really need to specify install-interface includes dependencies?

How do I install Node and NPM so I don't have to use sudo?

Why I don't do this regular expression?

Why can't I pass this method directly into the constructor, why do I need to use a lambda?

How do I deal with installing peer dependencies in Angular CLI?

Why do I need to import some class like Scanner and don't with class like Math (eclipse)

How do I use the Consul Agent CLI to create new KV entries but only if they don't already exist?

Why do I need mark for check ? angular

Do I need Angular CLI to develop Angular apps?

Why do I need use derivedStateOf in Compose?

Why do I need to use chroot

why do I need to use strdup()?

Why do i need NOT use the namespace?

Why do i need to use minitest/autorun?