How to create ng-packagr projects for specific Angular versions?

43 views Asked by At

We can create an Angular 10 project like this:

npx -p @angular/[email protected] ng new angular-project

However if we try to create a library project within this project errors like this are generated, since it seems it is trying to create a library for the latest version of Angular:

angular-project % ng g library test
Workspace extension with invalid name (defaultProject) found.
Workspace extension with invalid name (defaultProject) found.
Workspace extension with invalid name (defaultProject) found.
Workspace extension with invalid name (defaultProject) found.
CREATE projects/test/README.md (963 bytes)
CREATE projects/test/ng-package.json (153 bytes)
CREATE projects/test/package.json (208 bytes)
CREATE projects/test/tsconfig.lib.json (314 bytes)
CREATE projects/test/tsconfig.lib.prod.json (240 bytes)
CREATE projects/test/tsconfig.spec.json (273 bytes)
CREATE projects/test/src/public-api.ts (112 bytes)
CREATE projects/test/src/lib/test.component.spec.ts (582 bytes)
CREATE projects/test/src/lib/test.component.ts (278 bytes)
CREATE projects/test/src/lib/test.service.spec.ts (347 bytes)
CREATE projects/test/src/lib/test.service.ts (133 bytes)
UPDATE angular.json (4674 bytes)
UPDATE package.json (1287 bytes)
UPDATE tsconfig.json (526 bytes)
⠹ Installing packages (npm)...npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/jasmine-core
npm ERR!   dev jasmine-core@"~3.6.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer jasmine-core@">=3.8" from [email protected]
npm ERR! node_modules/karma-jasmine-html-reporter
npm ERR!   dev karma-jasmine-html-reporter@"^1.5.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! 
npm ERR! For a full report see:
npm ERR! /Users/xxxx/.npm/_logs/2023-11-23T18_58_14_418Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /Users/xxx/.npm/_logs/2023-11-23T18_58_14_418Z-debug-0.log
✖ Package install failed, see above.
0

There are 0 answers