I am running into an error after starting up a new project, which causes me to wonder whether I'm correctly reading the information I got online.
Following instructions from Angular and other sources about using Yarn as the packkage manager, I ran these commands:
npm install -g @angular/cli typescript less less-plugin-clean-css
ng version
ng config -g cli.packageManager yarn
ng new my-app
yarn add @angular/material @angular/cdk
yarn install
ng serve
At this point, after confirming that the Angular version was indeed the one I wanted, I thought the app generated by the Angular CLI would simply run. However, I get this error message:
Node packages may not be installed. Try installing with 'yarn install'. Error: Could not find the '@angular-devkit/build-angular:dev-server' builder's node package.
Having already run the suggested command, I went back to the Yarn documentation to double check the meaning of the command.
I am now wondering whether yarn's installation of the packages is compatible with what Angular expects. I am surprised to find very little information about this. Just about every search result speaks of installing packages with npm install
. If so, I wonder what's the point of using yarn.
I am clearly missing something to understand how Angular 19 is supposed to work with Yarn. The .angular-config.json file in my home directory has this:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"cli": {
"packageManager": "yarn",
"analytics": false
},
"version": 1,
"projects": {}
}
After much time spent on this, I've come to understand that Angular simply needs node_modules
to be present on the disk. The answer to my title question is No.
Solution: The project creation with ng new
ends without a .yarnrc.yml
file. This file needs to be created and it needs a line nodeLinker: node-modules
so that Yarn knows to persist the required files in the required node_modules
directory.
Side note: It's a sad state of affairs that even articles published this very year 2024 still reference either Yarn 1 or deprecated ways of doing things.