angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.72k stars 11.98k forks source link

1.1.0-rc.0 regression: wrong library bundled #6351

Closed achimha closed 7 years ago

achimha commented 7 years ago

Bug Report or Feature Request (mark with an x)

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

Versions.

@angular/cli: 1.1.0-rc.0 node: 6.10.2 os: linux x64 @angular/common: 4.1.2 @angular/compiler: 4.1.2 @angular/core: 4.1.2 @angular/forms: 4.1.2 @angular/http: 4.1.2 @angular/platform-browser: 4.1.2 @angular/platform-browser-dynamic: 4.1.2 @angular/router: 4.1.2 @angular/cli: 1.1.0-rc.0 @angular/compiler-cli: 4.1.2 -->

Repro steps.

My project bundles OpenLayers which is a monolithic JavaScript created by Closure compiler. With 1.1.0-rc.0 (but not any version before including up to 1.1.0-beta.1), it seems that incorrect code is emitted leading to a runtime error deep down in the library. From the looks of it, an identifier is not defined -- possibly incorrect tree-shaking?

I can reproduce it at will but given the complexity of the project, I am a bit at loss as to how to proceed the investigation.

achimha commented 7 years ago

It is both reproducible with ng serve and in an AOT production build.

achimha commented 7 years ago

I believe I found where the error is coming from. I captured the chunks emitted by the dev server for both beta 1 and rc 0 and compared them.

My usage of libraries as like this:

MyApp
  |-- angular2-openlayers
      |-- openlayers
  |-- openlayers

With beta 1 I see in my chunk:

var openlayers_1 = __webpack_require__("./node_modules/openlayers/dist/ol.js");

With rc 0, the same chunk only has one difference:

var openlayers_1 = __webpack_require__("./node_modules/angular2-openlayers/node_modules/openlayers/dist/ol.js");

It therefore takes the library openlayers from a subcomponent which has a different version than the one my app references.

achimha commented 7 years ago

So it's this change causing the issue: https://github.com/angular/angular-cli/pull/6276

clydin commented 7 years ago

What you are seeing is the correct behavior exposing a defect in either the dependency configuration of the project or one of the dependencies (in this case angular2-openlayers). angular2-openlayers has a pinned dependency on version 4.0.1 of openlayers which means that package has a requirement on that specific version and if the project also uses the openlayers package directly than it would need to also use that exact version. The angular2-openlayers package should probably use a more lenient versioning strategy; also, and most likely more ideally, it could use a peer dependency which would allow a project to use their preferred version of the package.

achimha commented 7 years ago

You are of course right. I've relaxed the openlayers dependency to

"openlayers": "4.0.x || 4.1.x"

Which is broad enough for users of the package and now rc 0 bundles the correction version of the library.

angular-automatic-lock-bot[bot] commented 5 years ago

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.