如果要全局设置它,请改用它:ng config -g cli.packageManager cnpm 如果尝试在本地设置它,则在ng new为您构建程序包时会遇到一些问题,直到完成此操作,您才需要配置本地程序包。

Angular CLI团队添加了一个新标记来选择--package-manager可以设置为的软件包管理器npm|yarn|pnpm|cnpm。这意味着当您使用如下命令创建新项目时,可以设置程序包管理器: ng new projectName --package-manager=yarn

原文: https://stackoverflow.com/questions/50897969/how-can-i-set-yarn-as-the-default-packagemanager-for-angular-cli-i-get-cannot

If you want to set this globally, use this instead: ng config -g cli.packageManager yarn If you are trying to set it locally you have a bit of a problem in that ng new builds your package for you, until you have done this you do not have a local package to configure.

-- Update --

As of Angular 11, the Angular CLI team added a new flag to pick the package manager --package-manager which can be set to npm|yarn|pnpm|cnpm. This means you can set the package manager when you create a new project with a command that would look something like: ng new projectName --package-manager=yarn