angular/angular-cli

ng build should not require @angular/* modules that are not used

Closed this issue ยท 6 comments

jrood commented

Bug Report or Feature Request (mark with an x)

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

Versions.

@angular/cli: 1.0.0
node: 6.9.5
os: darwin x64
@angular/common: 4.0.2
@angular/compiler: 4.0.2
@angular/core: 4.0.2
@angular/forms: 4.0.2
@angular/http: 4.0.2
@angular/platform-browser: 4.0.2
@angular/platform-browser-dynamic: 4.0.2
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.2

Repro steps.

ng new test-app
cd test-app
npm r --save @angular/router
ng build
It should return ERROR in Could not resolve module @angular/router
It should not be trying to resolve @angular/router if it is not being used.

Desired functionality.

When an application is not using the @angular/router, the ng cli should not attempt to resolve it.
Angular already aspires to be granular. It seems the purpose of splitting things up into /core /forms /http /router and so on is to let developers only include the parts they need. If the ng cli requires all these packages, even when they are not used, it seems that this purpose is thwarted.

I reproduced this behaviour with same versions, and got same error message.
This is a real issue.
#goodnessSquad

๐Ÿ‘

I tested myself and can verify it as well.

kamik@T460p MINGW64 /d/sandbox/master-project (master)
$ rm -rf ./node_modules/\@angular/router

kamik@T460p MINGW64 /d/sandbox/master-project (master)
$ ng build
Hash: 5f9283f0affda25610c6
Time: 9102ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 166 kB {4} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 52.8 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 65.2 kB {4} [initial] [rendered]
chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.09 MB [initial] [rendered]
chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]

ERROR in Could not resolve module @angular/router

I think this is related to how lazy route detection tries to find router tokens but there is no direct dependency on it.

Perhaps @ngtools/webpack should have a peer dependency on the router.

/cc @hansl

I can reproduce in 4.2.4 with 1.1.3 cli.

Dependency seems to come from [angular-cli, blueprints, compiler-cli]

hansl commented

The webpack plugin uses @angular/compiler-cli to get the list of lazy routes, which are used as code splitting points in the build. The Compiler CLI uses @angular/router to get the symbol that it looks for. This new PR will say there's no lazy routes if that error shows up.

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.