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 {}
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();
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
See also
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments