Angular-cli: ng update not compatible with yarn

Created on 27 Jul 2018  Â·  20Comments  Â·  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

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

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

Repro steps

We have been using yarn for some time now and it has been working fine.. but now with "ng update" it feels as yarn.lock file is not used properly?

Running ng update tells me @angular/cli needs update.. then running ng update @angular/cli does nothing but tell me that all looks good.. ?

To get rid of this issue I can just run npm install to generate the package-lock.json file and then run ng update @angular/cli and it works..

schematicupdate medium 1 (urgent) broken bufix

Most helpful comment

Using the lock file would be a potential optimization for installed package discovery, not a fix for any of the issues discussed in this thread.

All 20 comments

same issue here

Hi,

i am currently deciding wether to use npm or yarn for my angular project. I would prefer yarn. Therefore i would like to ask if the described problem still exist?

Regards, Annick

I'm still having this issue but adding --from=x.x.x to the command is a workaround.

Same issue. We don't even have npm installed because of some issues it has caused while using 100% yarn in our projects. The --from workaround doesn't seem to work either.

node_modules\@schematics\update\update\npm.js:44
                throw error;
                ^

Error: Command failed: npm get registry
'npm' is not recognized as an internal or external command,
operable program or batch file.

    at ChildProcess.exithandler (child_process.js:276:12)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:915:16)
    at Socket.stream.socket.on (internal/child_process.js:336:11)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at Pipe._handle.close [as _onclose] (net.js:561:12)

Please ensure that you have specified yarn as the project's package manager.

The following should be present within the angular.json file:

  "cli": {
    "packageManager": "yarn"
  }

I'm getting the same error, too. At the top of my angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "cli": {
    "packageManager": "yarn"
  },
  "projects": {

And in ~/.angular-config.json:

{
  "version": 1,
  "cli": {
    "packageManager": "yarn"
  }
}

@a01fe Do you have npm installed on the system?

Also, CLI version information would be incredible useful to attempt to troubleshoot the issue.

Unfortunately, some versions will require npm present on the system for ng update to work properly. This will be completely rectified along with greater support for .npmrc files with PR #12526.

@clydin No, npm is not installed. I manually updated @angular/cli with:

yarn global remove @angular/cli
yarn remove @angular/cli
yarn global add @angular/cli
yarn add @angular/cli --dev

Output from ng --version:


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / â–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.0.3
Node: 10.12.0
OS: darwin x64
Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    <error>
@angular-devkit/core         <error>
@angular-devkit/schematics   <error>
@schematics/angular          <error>
@schematics/update           <error>
rxjs                         <error>

Looks like a todo:
https://github.com/angular/angular-cli/blob/f52f043e4f423554d2f5b26e75c5a77e973ce8b2/packages/schematics/update/update/index.ts#L513

So the yarn on schematics is not supported, there is no class for it.

That’s related to discovery of installed packages. By that it means to read the lock file instead of manually crawling node modules.
Outside of reading a yarnrc file yarn works with update assuming npm is also installed currently to get registry options form any npmrc files present. But that will be fixed with the above mentioned PR. Which is unfortunately currently blocked on an upstream package PR.

Why not just use official lockfile package from yarn?
https://www.npmjs.com/package/@yarnpkg/lockfile

for NPM you could use (or clone, or make a new one):
https://github.com/uber/npm-shrinkwrap

Using the lock file would be a potential optimization for installed package discovery, not a fix for any of the issues discussed in this thread.

We also use Yarn exclusively in our repos, and I would be delighted if we could simply run ng update whenever we felt the need. Thanks in advance for tackling this.

ng update currently supports yarn usage within the repository. The latest version also supports yarn without npm being installed on the system.
Manually configuring the preferred package manager is also no longer necessary in most cases. The CLI will detect the presence of a yarn.lock file and prefer yarn if installed; assuming there is also not an npm (or soon pnpm) lock file also present. Note however that any configured option takes precedence.

Also, as to the original issue, ng update does not currently (or previously) use package manager lock files in its update logic (npm, yarn, pnpm, or otherwise).

To ng update with yarn:

ng update --packageManager=yarn

ng update --all --packageManager=yarn

To ng update with yarn:

ng update --packageManager=yarn

ng update --all --packageManager=yarn

Should not be needed if yarn is specified in angular.json

"cli": { "packageManager": "yarn" }

The configuration option is also not needed if a lock file is present within the project. With the exception of when both an npm AND yarn lock file are present; in which case the CLI will default to npm so the setting would be needed in that situation if yarn is preferred.

Closing this issue as yarn is fully supported with ng update. If any problems are still being encountering regarding the use of yarn, please open a new issue with up to date CLI versions and any details regarding the problem.

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._

Was this page helpful?
0 / 5 - 0 ratings