Angular not working after cloning to a different PC - node.js

so I got a new pc and I wanted to pass my angular project through github.
I used 1.npm i 2.npm i #angular/cli#latest -D 3. ng update
And Everytime I'm trying to run the project with ng s it keeps sending me this error:
This version of CLI is only compatible with Angular versions ^9.0.0-beta || >=9.0.0 <10.0.0,
but Angular version 8.2.14 was found instead.
Please visit the link below to find instructions on how to update Angular.
https://angular-update-guide.firebaseapp.com/
I tried using the instructions at the link.
This is my Angular version when typing ng --version:
Angular CLI: 9.0.1
Node: 12.16.0
This is the package.json:
{
"name": "empire-gaming",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular-redux/store": "^10.0.0",
"#angular/animations": "~8.2.14",
"#angular/cdk": "~8.2.3",
"#angular/common": "~8.2.14",
"#angular/compiler": "~8.2.14",
"#angular/core": "~8.2.14",
"#angular/forms": "~8.2.14",
"#angular/material": "^8.2.3",
"#angular/platform-browser": "~8.2.14",
"#angular/platform-browser-dynamic": "~8.2.14",
"#angular/router": "~8.2.14",
"#ng-bootstrap/ng-bootstrap": "^5.2.1",
"#ngrx/store": "^8.6.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"hammerjs": "^2.0.8",
"mongoose": "^5.8.10",
"ngx-bootstrap": "^5.3.2",
"redux": "^4.0.5",
"rxjs": "~6.4.0",
"tslib": "^1.10.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.803.22",
"#angular/cli": "^9.0.1",
"#angular/compiler-cli": "~8.2.14",
"#angular/language-service": "~8.2.14",
"#types/jasmine": "~3.3.8",
"#types/jasminewd2": "~2.0.3",
"#types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.5.3"
}
}
I'm really clueless about it... I would be glad if you help me.

The version of Angular that you are using in the project is lower than the version that needed for the latest version of Angular CLI.
I would recommend you to downgrade the Angular CLI version to 8.3.25
npm uninstall -g #angular/cli
npm cache clean
npm install -g #angular/cli#8.3.25
And change the version of Angular CLI in your devDependencies:
npm install -D #angular/cli#8.3.25

First step install Angular globally.
npm install -g #angular/cli#latest
Run Update command to get a list of all dependencies required to be upgraded.
ng update
Next Run update command as below for each individual Angular core package
ng update #angular/cli #angular/core
If you want to force the changes use: –force and –allow-dirty flags command additionally to fix all other pending issues.
ng update #angular/cli #angular/core --allow-dirty --force

This is worked for me
Delete folder node_modules and package-lock.json
then execute: "npm install"
in short:
go to project directory in terminal/command prompt and execute following commands
rm -fr ./node_modules
rm -fr ./package-lock.json
npm install
ng serve -o

I know this is an old thread, but in my experience changing the app package.json file("#angular-devkit/build-angular") to another compatible version works for me :). After the file change, you will be needed to run again these commands "ng update", "npm install" & "ng server"

Related

peer dependencies in npm

I got error regarding peer dependencies when I try to install package.json using "npm install".
Peer Dependency error
I have learned that I can use "npm install -legacy-peer-deps" from this link What does npm install --legacy-peer-deps do exactly? When is it recommended / What's a potential use case?.
But I know that "npm install --legacy-peer-deps" ignores peer dependencies so I am looking for different solutions for this error that I attached screenshot. I have tried to define "peerDependencies" in package.json to prevent dependency error but the different versions of the same package are shown as a dependency as shown below screenshot.
different versions of peer dependency
My package.json are shown as below. Would you help me about this problem? What do you suggest for peer dependency problems? When I want to add new packages to package.json, I will face the peer dependency problem again. Thanks.
{
"name": "metric-tutorial",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"#angular/animations": "~13.3.0",
"#angular/cdk": "^13.3.9",
"#angular/common": "~13.3.0",
"#angular/compiler": "~13.3.0",
"#angular/core": "~13.3.0",
"#angular/forms": "~13.3.0",
"#angular/material": "^13.3.9",
"#angular/platform-browser": "~13.3.0",
"#angular/platform-browser-dynamic": "~13.3.0",
"#angular/router": "~13.3.0",
"angular-material-fileupload": "^3.0.2",
"mathjax-angular": "^1.4.2",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"#angular-devkit/build-angular": "~13.3.1",
"#angular/cli": "~13.3.1",
"#angular/compiler-cli": "~13.3.0",
"#types/jasmine": "~3.10.0",
"#types/node": "^12.11.1",
"angular-cli-ghpages": "^1.0.0",
"jasmine-core": "~4.0.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.1.0",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"typescript": "~4.6.2"
}
}

Create a docker container from an angular project

I want to create a docker container based on my angular project.
This is my dockerfile:
# here we dockerize angular app
FROM node:12-alpine3.11
WORKDIR /usr/local/lib
COPY . /usr/local/lib/
RUN npm install
RUN npm run build
EXPOSE 4200
CMD [ "node", "server.js" ]
The dockerfile is located in the directory of my angular project containing all of the files except for node_modules.
When i try to build my docker image i reach the build stage and get this error:
"./node_modules/primeng/fesm2015/primeng-chart.js:4:0-34 - Error: Module not found: Error: Can't resolve 'chart.js/auto' in '/usr/local/lib/node_modules/primeng/fesm2015'"
this is my package.json
{
"name": "acm_jenkins_web",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"sonar-scanner": "sonar-scanner"
},
"private": true,
"dependencies": {
"#angular/animations": "^12.2.2",
"#angular/cdk": "^12.2.2",
"#angular/common": "~12.0.3",
"#angular/compiler": "~12.0.3",
"#angular/core": "~12.0.3",
"#angular/forms": "~12.0.3",
"#angular/platform-browser": "~12.0.3",
"#angular/platform-browser-dynamic": "~12.0.3",
"#angular/router": "~12.0.3",
"#ngx-translate/core": "^13.0.0",
"#ngx-translate/http-loader": "^6.0.0",
"bootstrap": "^3.0.0",
"chart.js": "^2.9.4",
"jquery": "^3.6.0",
"ngx-toastr": "^14.0.0",
"popper.js": "^1.16.1",
"primeicons": "^4.1.0",
"primeng": "^12.0.0-rc.1",
"rxjs": "~6.6.0",
"tslib": "^2.1.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"#angular-devkit/build-angular": "~12.0.3",
"#angular/cli": "~12.0.3",
"#angular/compiler-cli": "~12.0.3",
"#types/jasmine": "~3.6.0",
"#types/node": "^12.11.1",
"jasmine-core": "~3.7.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"typescript": "~4.2.3",
"sonar-scanner": "^3.1.0"
}
}
Did you try such steps on local machine (not docker)?
delete local node_modules folder completely
use npm i to install deps
run npm build on the local machine
In case you get the same issue, the reason can be installing incorrect version of this two packages and you can dig this way:
"chart.js": "^2.9.4",
...
"primeng": "^12.0.0-rc.1",
Othervise you can save package-lock.json after steps above and try to run npm ci command instead of npm install.
It should help if there's sth incorrect with deps

How to run "npm install" to create node_modules folder for an older Angular project?

I'm pulling our code down from our repository to a new laptop. Our project was built on Angular 5 last year. Of course, the new laptop has the latest and greatest Angular CLI, NodeJS, and NPM tools install, and Angular 6 was just released. The laptop has Node 8.11.2, NPM 5.6.0, and Angular CLI 6.0.3.
When I run "npm install" to get the "node_modules" folder on my new laptop for this project, I'm getting all kinds of errors and warnings and unable to create the node_modules folder successfully (see image attached). What can I do to get this project running. I don't necessarily care about upgrading to Angular 6 at this time. I simply need to continue to be able to run and develop this project.
Our package.json:
{
"name": "my-first-app",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --environment=local --open",
"build": "ng build --prod aot=false",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "^5.2.0",
"#angular/cdk": "^5.2.4",
"#angular/common": "^5.2.0",
"#angular/compiler": "^5.2.0",
"#angular/core": "^5.2.0",
"#angular/forms": "^5.2.0",
"#angular/http": "^5.2.0",
"#angular/material": "^5.2.4",
"#angular/platform-browser": "^5.2.0",
"#angular/platform-browser-dynamic": "^5.2.0",
"#angular/router": "^5.2.0",
"#ngui/map": "^0.20.2",
"#types/googlemaps": "^3.30.7",
"bootstrap": "^4.0.0",
"core-js": "^2.4.1",
"google-maps-coords": "^1.0.0",
"jquery": "^3.3.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"#angular/cli": "~1.7.1",
"#angular/compiler-cli": "^5.2.0",
"#angular/language-service": "^5.2.0",
"#types/jasmine": "~2.8.3",
"#types/jasminewd2": "~2.0.2",
"#types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"font-awesome": "^4.7.0",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
}
I faced a similar issue and removing the package-lock.json and running npm install solved it for me.
First Clean the cache
npm cache clean --force
Then Install It
npm install
It is actually very simple. Just do a sudo npm install node_modules if you are using Mac/Linux or just a npm install node_modules on windows.

Getting error while running an angular4 existing project in ubntu system

I am getting the following error while running the angular4 existing project in my system.
Error:
subrajyoti#subrajyoti-H81M-S:/var/www/html/angular4_project/XSS-DOM/vulnerable$ ng serve
As a forewarning, we are moving the CLI npm package to "#angular/cli" with the next release,
which will only support Node 6.9 and greater. This package will be officially deprecated
shortly after.
To disable this warning use "ng set --global warnings.packageDeprecation=false".
You have to be inside an angular-cli project in order to use the serve command.
I have installed node version 9.4.0 and npm version 5.6.0 and installed the angular cli like this sudo npm install #angular/cli. There was a existing project when I run this project by typing the command ng serve it gave me the above error. I have already inside the project folder but still getting this error. my package.json file is given below.
{
"name": "crud-project",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "^5.2.0",
"#angular/common": "^5.2.0",
"#angular/compiler": "^5.2.0",
"#angular/core": "^5.2.0",
"#angular/forms": "^5.2.0",
"#angular/http": "^5.2.0",
"#angular/platform-browser": "^5.2.0",
"#angular/platform-browser-dynamic": "^5.2.0",
"#angular/router": "^5.2.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"#angular/cli": "1.6.8",
"#angular/compiler-cli": "^5.2.0",
"#angular/language-service": "^5.2.0",
"#types/jasmine": "~2.8.3",
"#types/jasminewd2": "~2.0.2",
"#types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
}
Please help me to resolve this error.
You are using a very old unsupported version of the CLI. You should update the the latest one or you can migrate it as described here if you have existing project

NPM peer dependencies - options for resolution?

First-off, I am new to NodeJs and NPM so thanks in advance for any clarification that anyone can offer me.
This is a question about peer dependencies and warnings given by NPM during package installs. The NPM docs and other questions on StackOverflow don't seem to answer my exact questions about what I can/should do to resolved these dependency issues.
Actually, Everything I have tried seems to have made things worse I am now completely confused.
Starting from a fresh install of the latest Angular CLI I created a new Angular 5 project. To this I have added Angular Material.
When I added Angular flex-layout I got the following warnings:
npm WARN #angular/flex-layout#2.0.0-beta.10-4905443 requires a peer of #angular/core#~4.4.4 but none is installed. You must install peer dependencies yourself.
npm WARN #angular/flex-layout#2.0.0-beta.10-4905443 requires a peer of #angular/common#~4.4.4 but none is installed. You must install peer dependencies yourself.
Adding angular-split adds the following:
npm WARN angular-split#0.2.7 requires a peer of #angular/common#^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN angular-split#0.2.7 requires a peer of #angular/core#^4.0.0 but none is installed. You must install peer dependencies yourself.
I have done some successful experiments with angular-layout but angular-split does not seem to be working correctly. The examples on the author's website are fine so I suspect that this might be because it doesn't have the Angular version it is expecting.
Do these warnings imply that I can install the required versions of Angular components side-by-side with the primary versions used by my code to satisfy these libraries' requirements?
Alternatively, do they really mean that flex-layout and angular-split are not fully compatible with the version of Angular that I am using (and therefore I can't use them until they are updated).
In summary, can different versions of the same module co-exist in a project, and if so, what steps do I need to take because all I have done so far is get myself in a dreadful mess.
This is what my packages.json file looks like:
{
"name": "angular-test4",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "^5.0.0",
"#angular/cdk": "^5.0.0-rc.2",
"#angular/common": "^5.0.0",
"#angular/compiler": "^5.0.0",
"#angular/core": "^5.0.3",
"#angular/flex-layout": "^2.0.0-beta.10-4905443",
"#angular/forms": "^5.0.0",
"#angular/http": "^5.0.0",
"#angular/material": "^5.0.0-rc.2",
"#angular/platform-browser": "^5.0.0",
"#angular/platform-browser-dynamic": "^5.0.0",
"#angular/router": "^5.0.0",
"angular-split": "^0.2.7",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"#angular/cli": "1.5.4",
"#angular/compiler-cli": "^5.0.0",
"#angular/language-service": "^5.0.0",
"#types/jasmine": "~2.5.53",
"#types/jasminewd2": "~2.0.2",
"#types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2"
}
}

Resources