Skip to content

yarn fails to handle angular-cli 1.2.4 dependencies correctly #7136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rightisleft opened this issue Jul 25, 2017 · 26 comments
Closed

yarn fails to handle angular-cli 1.2.4 dependencies correctly #7136

rightisleft opened this issue Jul 25, 2017 · 26 comments
Assignees

Comments

@rightisleft
Copy link

rightisleft commented Jul 25, 2017

Bug Report or Feature Request (mark with an x)

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

Versions.

@angular/cli: 1.2.4
node: 6.11.1
os: linux x64
@angular/common: 4.3.1
@angular/compiler: 4.3.1
@angular/core: 4.3.1
@angular/forms: 4.3.1
@angular/http: 4.3.1
@angular/platform-browser: 4.3.1
@angular/platform-browser-dynamic: 4.3.1
@angular/router: 4.3.1
@angular/cli: 1.2.4
@angular/compiler-cli: 4.3.1

Repro steps.

package.json

...
  "private": true,
  "dependencies": {
    "@angular/common": "^4.3.1",
    "@angular/compiler": "^4.3.1",
    "@angular/core": "^4.3.1",
    "@angular/forms": "^4.3.1",
    "@angular/http": "^4.3.1",
    "@angular/platform-browser": "^4.3.1",
    "@angular/platform-browser-dynamic": "^4.3.1",
    "@angular/router": "^4.3.1",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.28",
    "@types/tinycolor": "^1.1.27",
    "angular2-loaders-css": "1.0.5",
    "cerialize": "0.1.13",
    "core-js": "^2.4.1",
    "msgpack-lite": "^0.1.26",
    "ng2-charts": "^1.6.0",
    "ng2-page-scroll": "^4.0.0-beta.3",
    "ng2-select": "^1.2.0",
    "ng2-toasty": "4.0.0",
    "puse-icons-feather": "^1.1.0",
    "reflect-metadata": "0.1.9",
    "rxjs": "^5.1.0",
    "tinycolor2": "^1.4.1",
    "ts-helpers": "1.1.1",
    "typeorm": "0.0.9",
    "typescript": "^2.2.0",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@angular/cli": "^1.2.4",
    "@angular/compiler-cli": "^4.3.1",
    "@types/jasmine": "2.5.38",
    "@types/node": "6.0.42",
    "bootstrap": "4.0.0-alpha.6",
    "codelyzer": "~2.0.0-beta.1",
    "font-awesome": "4.7.0",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "2.0.0",
    "karma-cli": "1.0.1",
    "karma-jasmine": "1.0.2",
    "karma-remap-istanbul": "0.2.1",
    "protractor": "~4.0.13",
    "ts-node": "2.1.0",
    "tslint": "4.3.0"
  }
}

$ yarn list enhanced-resolve                                                                                                                                                                                                                                                           yarn list v0.24.6
└─ [email protected]

`$ng build --prod `

The log given by the failure.

[root@4bc7c5f8560c PiensoWeb]# ng build --prod
Hash: 381eeb7f2d84ab2dfd29
Time: 19189ms
chunk    {0} styles.ff557a508943300e7e5d.bundle.css (styles) 440 bytes {4} [initial] [rendered]
chunk    {1} main.c242e4a20e66c8a77083.bundle.js (main) 1.76 kB {3} [initial] [rendered]
chunk    {2} scripts.2264c5f19ef83b4b557f.bundle.js (scripts) 152 kB {4} [initial] [rendered]
chunk    {3} vendor.89b6466bbf579cad9ebd.bundle.js (vendor) 1.08 MB [initial] [rendered]
chunk    {4} inline.33937348cd092eeba28e.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/godata/pipelines/PiensoWeb/src'
 @ ./src/main.ts 4:0-74
 @ multi ./src/main.ts

Desired functionality.

When i run this on OS X it works fine.

$ng -v                                                                                                                                                                                                                                                                                        
@angular/cli: 1.2.4
node: 6.11.0
os: darwin x64
@angular/common: 4.3.1
@angular/compiler: 4.3.1
@angular/core: 4.3.1
@angular/forms: 4.3.1
@angular/http: 4.3.1
@angular/platform-browser: 4.3.1
@angular/platform-browser-dynamic: 4.3.1
@angular/router: 4.3.1
@angular/cli: 1.2.4
@angular/compiler-cli: 4.3.1

$ng build --prod                                                                                                                                                                                                                                                                          
Hash: 3b14b67673dd8ca9ba26
Time: 41531ms
chunk    {0} main.8683891522fecb4ec38d.bundle.js (main) 591 kB {3} [initial] [rendered]
chunk    {1} styles.ff557a508943300e7e5d.bundle.css (styles) 440 bytes {4} [initial] [rendered]
chunk    {2} scripts.9a8757e99ae6e1dcb456.bundle.js (scripts) 152 kB {4} [initial] [rendered]
chunk    {3} vendor.c61629386e8e347207a2.bundle.js (vendor) 4.9 MB [initial] [rendered]
chunk    {4} inline.25beaa585d007a77a7d7.bundle.js (inline) 0 bytes [entry] [rendered]

Mention any other details that might be useful.

Yarn packages && node_modules deleted and reinstall on each linux build

@Fayde
Copy link

Fayde commented Jul 25, 2017

I had this problem this morning on windows, updating my node version to latest and the cli to 1.2.4 solved the issue, though

@rightisleft
Copy link
Author

Seems like this is definitely related to enhanced-resolve

Builds that work do not have:

/Users/jmurphy/projects/ubq/web/node_modules/@ngtools/webpack/node_modules/enhanced-resolve

@rightisleft
Copy link
Author

rightisleft commented Jul 25, 2017

Weird - today im seeing the following on the failed builds

[me@ae7b3ab2f8b7]# yarn list enhanced-resolve @angular/cli
yarn list v0.27.5
├─ @angular/[email protected]
├─ [email protected]
└─ [email protected]
   └─ [email protected]

@rightisleft
Copy link
Author

rightisleft commented Jul 25, 2017

This does seem to be isolated to yarn.

Running the following works:

$ rm -rf node_modules
$ npm install
$ npm run buildprod


Running the following fails:

$ rm -rf node_modules
$ yarn install
$ npm run buildprod


The bug here is to make this work with yarn

@rightisleft rightisleft changed the title ng build prod works on os x and fails on linux yarn fails to handle angular-cli 1.2.4 dependencies correctly Jul 25, 2017
@pschmoek
Copy link

yarn resolves 2 versions of enhanced-resolve.
Angular CLI uses webpack which has dependency enhanced-resolve "^3.3.0". This leads to 2 entries in yarn.lock - resolving 2 different versions of enhanced-resolve. One given to Angular CLI - the correct one 3.3.0 - and one given to webpack 3.4.1 - the faulty one.
Just run yarn and change yarn.lock by hand afterwards.

- [email protected]:
-   version "3.3.0"
-   resolved "YARN_REGISTRY_OR_YOUR_PRIVATE"
-   dependencies:
-     graceful-fs "^4.1.2"
-     memory-fs "^0.4.0"
-     object-assign "^4.0.1"
-     tapable "^0.2.5"

- enhanced-resolve@^3.3.0:
-   version "3.4.1"
-   resolved "YARN_REGISTRY_OR_YOUR_PRIVATE"
-   dependencies:
-     graceful-fs "^4.1.2"
-     memory-fs "^0.4.0"
-     object-assign "^4.0.1"
-     tapable "^0.2.7"

+ [email protected], enhanced-resolve@^3.3.0:
+   version "3.3.0"
+   resolved "YARN_REGISTRY_OR_YOUR_PRIVATE"
+   dependencies:
+     graceful-fs "^4.1.2"
+     memory-fs "^0.4.0"
+     object-assign "^4.0.1"
+     tapable "^0.2.5"

@flauc
Copy link

flauc commented Jul 26, 2017

It looks like when ever I run yarn again the yarn.lock file gets rebuild. Is there a way to make this stick?

@ankeshdave
Copy link

ankeshdave commented Jul 26, 2017

@flauc did you try yarn --freeze-lock-file after modifying yarn.lock?

@pschmoek
Copy link

yarn only modifies yarn.lock if you add or upgrade a dependency. Running yarn does not change the yarn.lock - that is the point of having a lock file. So the fix only stops working if you upgrade @angular/cli or add webpack, etc.

@flauc
Copy link

flauc commented Jul 26, 2017

It looks like only doing this prevents the yarn.lock file from being recreated:

yarn install --pure-lockfile

@markmaynard
Copy link

I was seeing the similar issues with enhanced-resolve yesterday with npm. It looks like the ^ dep on enhanced-resolve caused ngtools/webpack to change locally from [email protected] -> [email protected]. There must be a breaking change in enhanced-resolve somewhere.

@orestes
Copy link

orestes commented Jul 26, 2017

The lockfile changes for me too if I run yarn install. It shouldn't, but it does...

@zsparal
Copy link

zsparal commented Jul 26, 2017

@pschmoek @flauc @orestes Yarn can regenerate the lockfile on yarn install if it

  1. finds something in the package.json that's not in the lockfile
  2. Cannot resolve something according to the existing yarn.lock file

I came to the same conclusion as @pschmoek regarding the workaround but you need to be mindful about how you modify the yarn.lock file. You should have 2 lines starting with enhanced-resolve:

[email protected]:
enhanced-resolve@^3.x.x:

It's important that you don't change the version in the second one when merging the two lines:

[email protected], enhanced-resolve@^3.x.x:

Yarn should not regenerate your lockfile after these modifications.

Edit: just as an example: @pschmoek's diff uses ^3.3.0 but for me, a freshly generated yarn.lock contains ^3.0.0. If I were to copy-paste the workaround from here my lockfile would also change on yarn install.

@leovo2708
Copy link

Is this problem of yarn or of something? I am using yarn instead of npm because of better performance. But with npm, we get no problem in this case. I think this is not an issue of @angular CLI. Did we have to post an issue about this problem on yarn github? Or any other solutions here or come back npm?

Please give your idea. Thanks.

@attilacsanyi
Copy link

Hi guys!

No problem for me in case of node v8.2.1 and npm 5.3.0 after run npm i.
Problem just happen in case of yarn.

@filipesilva
Copy link
Contributor

filipesilva commented Jul 27, 2017

Hey all,

As far as I can tell, this is indeed a problem with yarn, and as @pschmoek described: given two dependencies ([email protected] and enhanced-resolve@^3.3.0), yarn resolves both 3.4.1 and 3.3.0 while npm resolved only to 3.3.0.

It's worth nothing that this only happens with newer versions of yarn. Older versions (like 0.24.6) seem to be fine:

$  rm -rf node_modules/ package-lock.json yarn.lock && npm -v && npm i && npm ls enhanced-resolve
5.3.0
# ...
[email protected] D:\sandbox\master-project
`-- @angular/[email protected]
  +-- @ngtools/[email protected]
  | `-- [email protected]
  `-- [email protected]
    `-- [email protected]  deduped

$  rm -rf node_modules/ package-lock.json yarn.lock && yarn --version && yarn && yarn list enhanced-resolve && yarn why enhanced-resolve
0.24.6
# ...
yarn list v0.24.6
└─ [email protected]
Done in 0.83s.
yarn why v0.24.6
[1/4] Why do we have the module "enhanced-resolve"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
info Reasons this module exists
   - "@angular/cli#@ngtools/webpack" depends on it
   - "@angular/cli#webpack" depends on it
Done in 0.87s.

If someone has an issue on the yarn tracker about this I'd love to have it linked here.

Currently my stance is that this is indeed a yarn problem: it is not resolving and deduping the versions properly.

I'll keep this issue opened to make it easier to direct people to it, but there is no action to take on the CLI.

EDIT: @ryzy reports that even with [email protected] the resolution is still not working: #7113 (comment)

@davidmehren
Copy link

@filipesilva There is a yarn issue about this, opened by @BorntraegerMarc yarnpkg/yarn#4024
They concluded that this is not a yarn problem.

@BorntraegerMarc
Copy link

yarnpkg/yarn#4024 FYI @filipesilva

@filipesilva
Copy link
Contributor

Thanks @davidmehren and @BorntraegerMarc. I went through it and think there are some very good points there (reliance on hoisting and the absence of peer dependencies).

I'm trying to figure out where that leaves us and what can be done on the short term. Will update as soon as I have news.

@filipesilva
Copy link
Contributor

filipesilva commented Jul 27, 2017

We're trying to get a new fix released today (#7169), under 1.2.6/1.3.0-rc.3. We hope that it will allow [email protected] and below to resolve correctly even under yarn.

@filipesilva
Copy link
Contributor

The versions have been released. Please let me know if you still run into problems with yarn.

@cebor
Copy link
Contributor

cebor commented Jul 27, 2017

Works for me.

Big Thanks @filipesilva !!!

@rybaczewa
Copy link

Can confirm, 1.2.5 was broken, 1.2.6 works fine for me.

@orestes
Copy link

orestes commented Jul 28, 2017

@angular/cli 1.2.6 working like a charm. Thanks!

@filipesilva
Copy link
Contributor

Closing then, this seems to be sorted.

@BorntraegerMarc
Copy link

@filipesilva I think you accidentally opened the issue again. It works like a charm for me now as well with yarn 0.27.5

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests