Compiling “Getting Started with Angular Signals” Code Lab Locally
It was easy to follow "Getting Started with Angular Signals" tasks with the online StackBlitz development environment, but as a practice exercise I wanted to get it up and running on my own computer. This turned out to be more challenging than expected, with several problems I had to fix before I could install dependencies on my computer with "npm install
".
Successful installation of project dependencies moved me to the next part of the challenge: Angular project issues. Running "ng serve
" resulted in the following error:
Error: Schema validation failed with the following errors:
Data path "" must have required property 'tsConfig'.
Unfortunately, there was no filename associated with this error message, so it took a lot of wrong turns before I found the answer. I compared files between my Compass project and this demo project and eventually figured out this was referring to the "build"/"options"
section in angular.json
. In my Compass project, I had a "tsConfig
" entry pointing to a file tsconfig.app.json
. This code lab exercise project's angular.json
is missing that entry and missing the file tsconfig.app.json
. I copied both from my Compass project to reach the next set of errors:
Error: src/cipher/cipher.ts:1:21 - error TS2305: Module '"@angular/core"' has no exported member 'effect'.
1 import { Component, effect, OnInit } from '@angular/core';
This is just the first of several errors, all complaining that the newfangled Angular signal mechanisms signal
, computed
, and effect
were missing from @angular/core
. Well, of course they wouldn't be. The packages.json
file specified Angular 15, and signals were one of the new touted features of Angular 16. Running "ng update
" I was informed of the following:
Using package manager: npm
Collecting installed dependencies...
Found 25 dependencies.
We analyzed your package.json, there are some packages to update:
Name Version Command to update
--------------------------------------------------------------------------------
@angular/cdk 15.2.9 -> 16.0.1 ng update @angular/cdk
@angular/cli 15.2.8 -> 16.0.2 ng update @angular/cli
@angular/core 15.2.9 -> 16.0.3 ng update @angular/core
@angular/material 15.2.9 -> 16.0.1 ng update @angular/material
So I ran "ng update @angular/cdk @angular/cli @angular/core @angular/material
". It was mostly successful but there was one error:
Migration failed: Tsconfig cannot not be read: /src/tsconfig.spec.json
See "/tmp/ng-QdC8Cc/angular-errors.log" for further details.
Judging by the "spec.json
" suffix this has something to do with Angular testing and I will choose to ignore that error. Now when I run "ng serve" I no longer get complaints about missing Angular signal mechanisms. I get syntax errors instead:
./src/cipher/guess/letter-guess.ts-2.css?ngResource!=!./node_modules/@ngtools/webpack/src/loaders/inline-resource.js!./src/cipher/guess/letter-guess.ts - Error: Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
SyntaxError
(17:5) /workspaces/codelabs/src/cipher/guess/letter-guess.ts Unclosed block
15 | }
16 |
> 17 | p {
| ^
18 | font-size: clamp(16px, 3vw, 20px);
19 | margin: 0;
./src/secret-message/secret-message.ts-5.css?ngResource!=!./node_modules/@ngtools/webpack/src/loaders/inline-resource.js!./src/secret-message/secret-message.ts - Error: Module build failed (from ./node_modules/postcss-loader/dist/cjs.js):
SyntaxError
(87:10) /workspaces/codelabs/src/secret-message/secret-message.ts Unknown word
85 | font-size: clamp(10px, 3vw, 20px);
86 |
> 87 | // color: #c0e0c7;
| ^
88 | text-shadow: -1px -1px 1.2px rgb(255 255 255 / 50%), 1px 1px 1px rgb(1 1 1 / 7%);
89 | background: transparent;
This sample project has component CSS as string literals inside the TypeScript source code files. This is a valid approach, but these bits of CSS were broken. For the first one, the paragraph style didn't have a closing brace, exactly as the error message complained. Adding a closing brace resolved that error. The second stylesheet error used double-slash comment style which isn't how CSS comments work. Changing that over to /* comment */
style resolved that error. After all of those changes, the little cipher app is up and running onscreen with some visual errors relative to what I saw for the same project StackBlitz.
How did StackBlitz run despite these problems? I'm going to guess that it has its own default tsconfig
and did not require one to be specified. In the repository package.json
I see that @angular/core
was specified as "next
". Apparently StackBlitz interpreted that to be something new that included signals, whereas my local machine decided "next
" is the same "15.2.9
" as everything else which did not. As for the CSS syntax errors... I have no guesses and that remains a mystery to me.
But at least now I have something running locally, and I got a useful exercise understanding and fixing Angular build errors. Now onward to fixing runtime errors.
My code changes are made in my fork of the code lab repository in branch signals-get-started
.