appsody / stacks

Appsody application stacks. This repo will be archived soon.
https://appsody.dev
Apache License 2.0
89 stars 120 forks source link

ng serve "ng" not found in existing Angular project using appsody run #605

Open karimbzu opened 4 years ago

karimbzu commented 4 years ago

I have observed two issues:

  1. unable to run existing Angular project with nodejs template using appsody
  2. in another attempt, successfully run Angular project but "ng" command not found therefore container does not come up.

Here is the details:'

I am using the following Angular project to containerize using appsody. https://github.com/wkrzywiec/aston-villa-app.git I applied the following commands.

appsody init nodejs none

appsody run

(this command always update "@angular-devkit/build-angular": "^0.803.23", to its latest version in packages.json whereas my existing application requires an old version of angular-devkit, i dont know why its happening maybe its default behavior??? how can we set our angular packages in appsody so that appsody should listen to our user-defined packages while running)

If i update all the angular packages using #ng update @angular/cli @angular/core --allow-dirty

appsody run gives me the following error:

image

But if i downgrade angular cli version using npm -g install @angular/cli@8.0.1 npm install @angular/cli@8.0.1

it successfully executes "appsody run" however, inside container the ng command not found error message appears. image

I think the issue is with my existing project structure, can anyone give me an expert opinion regarding the issue???

neeraj-laad commented 4 years ago

Appsody uses tries to use the same version as specified in package.json and package-lock.json as much as possible.

It does try to run npm audit fix to fix any vulnerabilities on top and I wonder if that is the reason for your module getting upgraded.

I tried cloning your git project and then ran npm audit to see what packages had issues and I see this:

found 24 vulnerabilities (4 low, 5 moderate, 15 high) in 40743 scanned packages
  run `npm audit fix` to fix 21 of them.
  3 vulnerabilities require semver-major dependency updates.

A lot of these are in @angular-cli, @angular-devkit.

Can you try to resolve these issues locally and then try appsody?

karimbzu commented 4 years ago

thank you @neeraj-laad for your prompt response. I tried to fix all the npm issues and then i tried to run #appsody run, the following error appeared: image

Can you please suggest some thing?

karimbzu commented 4 years ago

Tried another project with the latest Angular packages involved: https://github.com/ganatan/angular-example-starter.git Below are the steps and the outputs:

  1. git clone https://github.com/ganatan/angular-example-starter.git
  2. appsody init nodejs none
  3. appsody run image
  4. tried locally using npm and succeeded.
  5. npm install
  6. npm start image image

I dont know what is wrong with angular projects while doing appsody run. Waiting for the kind response.

neeraj-laad commented 4 years ago

@sam-github @andrewhughes101 You might want to chime in here.

No9 commented 4 years ago

Just looking at this and there seems to be a few of problems.

The error in the comment https://github.com/appsody/stacks/issues/605#issuecomment-575673440 seems to be caused by angular cli needing to be installed globally but the 'node' user doesn't have permissions. Seems to be a fairly common problem: https://github.com/angular/angular-cli/issues/16208 https://github.com/angular/angular-cli/issues/14584

One way to resolve this would be to add

RUN npm config set prefix '~'
ENV PATH=${PATH}:~/bin

After the user is set in the Dockerfile. This would install ng into /home/node/bin and it should make it available to the rest of the scripts

The ng server currently runs on 4200 but that isn't exposed so the app won't be accessible.

But I think there is a deeper aspect. The behaviour for appsody build should be different than appsody run as npm run build needs to be executed to generate the dist folder. The dist folder should then be moved to a predefined webserver such as nginx/express as ng serve used for development is not suitable for production hosting. https://github.com/angular/angular-cli/issues/5274

I can make a PR for the Dockerfile changes that will get appsody run to work but my suggestion would be to create a specific stack for frontend SPA hosting.