3

The node is already installed (v. 19.4) as well the npm (v. 9.2.0).

The Angular use as the default port 4200.

I set the 4200 port in the port item of the Codespace of my repository.

Then, I type on Codespace's CMD "ng serve".

I was expecting the main page of Angular showing up on Chrome.

Nevertheless, what happens is a 502 ERROR.

8 Answers8

5

I've been able to get Angular running in Codespaces by changing the Node version to 16.13. NVM comes pre-installed, so all you need is:

nvm install 16.13

npm install -g @angular/cli

ng serve

Meqwz
  • 1,319
  • 8
  • 14
2

Here is what I have working on my code space: Under the "scripts" section in package.json add the following script :

"start-on-codespaces": "ng serve --project=your-project-name --host=0.0.0.0 --disable-host-check",

When I run this script on the console, I then click on the localhost Url that is displayed in the console output.

Robert Dean
  • 3,193
  • 3
  • 25
  • 29
1

ng serve --host=0.0.0.0 is enough to run the project. You also need to forward port 4200 and make it public.

To reach the Jasmine test page you need to enable port 9876, however, the Jasmine instance fails to find the Angular serve instance. I'm looking for a Jasmine configuration or command parameter that would fix this.

1

It worked for me:

nvm install 16.13
npm install -g @angular/cli
ng serve
1

What has worked for me, summer 2023, is to use this:

npm run start -- --host=0.0.0.0 --public-host=${CODESPACE_NAME}-4200.preview.app.github.dev

I don't know why ng serve with the same options doesn't work but npm run does. I'm still learning angular and node.

Basil
  • 123
  • 8
0

As per angular documentation -

Angular requires an active LTS or maintenance LTS version of Node.js.

So accordingly, I have tested with all the LTS versions, but it only worked for v16.19.1 for me.

Is there a compatibility list for Angular / Angular-CLI and Node.js?

0

The Angular CLI requires a minimum NodeJS version of either v14.20, v16.14 or v18.10.

nvm install 14.20 | 16.14 | 18.10

nvm install 18.10

npm install -g @angular/cli

ng serve
zforgo
  • 2,508
  • 2
  • 14
  • 22
rodolfo
  • 1
  • 1
0

I invested several hours this week resolving the ng serve issue within GitHub codespaces using the latest LTS version of Node (18.17.0). Through numerous trials, I've gathered a few noteworthy observations:

  1. The command --host=0.0.0.0 --disable-host-check proves to be indispensable.
  2. Despite my repeated attempts, the default port 4200 failed to function effectively.
  3. Simply altering the port did not yield a resolution.

Ultimately, I managed to devise a successful solution by combining --host=0.0.0.0 --disable-host-check with a port change, which produced the desired outcome:

ng serve --host=0.0.0.0 --disable-host-check --port=3000

Throughout my endeavors, I discovered that any port, except for 4200, performed as expected.

Augusto Icaro
  • 553
  • 5
  • 15