node wont update angular - node.js

I have been struggling for days to try and get angular to update. I have finally narrowed it down to the fact when I run
ng new
it creates an angular app using version 1.7.4 but I have updated angular to version 8.1.2. when I run
ng --version
I get the message "your global version is 8.1.2 is greater than your local version 1.7.4 the local version will be uses"
I have run npm
npm update -g#angular/cli
npm update #angular/cli
but nothing. I have also deleted the files in
c:\users\user\appdata\roaming\npm\node_modules\#angular
and tried running
npm install #angular/cli
Has anyone got any idea either how to update my local install of angular or when I run
ng new
to get it to use the global version?
Thanks

npm update will update your package to the latest safe version, i.e. it won't increase a major version of your current package which is 1 in your case. A change of a major version means there will be breaking changes.
So you need to explicitly specify the package version to which you want to migrate. I.e. npm update #angular/cli#^8.1.2 or npm install #angular/cli#^8.1.2, sorry I mostly use yarn so not sure which of these 2 commands will work.

Related

NG command is displaying incorrect node version

I am getting below error when I tried to use ng command
Node.js version v11.13.0 detected.
The Angular CLI requires a minimum Node.js version of either v10.13 or v12.0.
Please update your Node.js version or visit https://nodejs.org/ for additional instructions.
When I try to see the node version using node -v, I see node version on my machine is v12.18.3
So from where ng is getting v11.13.0? How do I resolve this issue?
I tried below steps
Clear the NPM cache
Uninstall both node versions from the NVM
Uninstall anything that starts with node in Control Panel\Programs and Features
Install required node versions in NVM
Install Angular CLI
and things started working for me.
Had the same issue. It turns out installed Angular CLI was not compatible with the installed node and npm version. I used the https://stackoverflow.com/a/60258560 to check the compatibility. Then performed following steps:
Uninstall Angular cli
Uninstall Node and NVM
Installed Node version I wanted (10.x).
Installed specific Angular version corresponding to Node v10 which was Angular Cli v11 at this time.
I was also facing the same issue in my Windows machine where the node -v version and the version picked up by ng command were different. This was because my node.js command prompt was picking the version from AppData\Roaming\npm folder. Cleaning up this folder fixed the issue for me.
Uninstall node
Empty the contents from C:\Users<user>\AppData\Roaming\npm
Install the required node version

Unexpected end of JSON input error when creating new project

Each time I use angular/cli to create a new project by launching the following command
ng new Project-Name
I get the following error
npm ERR! Unexpected end of JSON input while parsing near '...-4","#angular/common"'
I tried to force clean the cache and re-try but still face the same problem.
NodeJS version: 12.16.3
npm version: 6.14.4
Angular CLI version: 9.1.4
OS: Windows 10 Home win32 x64
Edit: All the commands above I run them in Powershell as administrator
This is not a definitive answer but it looks like your global packages are corrupted in some way.
This bug may be caused by many different things. I suggest doing the following.
Install Node Version Manager (or NVM for Windows) and install Node version 10.16.1. This is enough for angular 9 and from my experience it is the most stable version for development. This should also change your NPM version so that may also help.
Uninstall global angular package npm uninstall -g #angular/cli
Force clear cache npm cache clean --force
Just to double check npm cache verify
You can also try clearing your %temp% and %roaming% AppData/npm-cache
install latest angular package npm install -g #angular/cli#<your-version>
if this error still occurs, consider using another shell
If this don't solve the problem try to manually locate the package.json file that is throwing an error and investigate.

npm installing wrong version of anuglar(8.1.0)

when i run the following command, it shows 6.4.1.
npm run ng --version
but when i am running the following command, it is installing 8.1.0 and getting error. i do not understand how it is happening.
npm install -g #angular/cli
i tried the following commands. but it is not working
npm cache clean --force
npm install -g #angular/cli
Error Screen
My Requirement:
Angular 6
how can i resolve this?
You should the latest (12+) node when upgrading to angular 8. You can download it from here.
After upgrading node, the issues should go away.
For simple use cases and thanks to the work done in Angular 8, you can upgrade to the latest release using one command:
$ ng update #angular/cli #angular/core
After running this command, the lazy loaded routes will be automatically migrated to the new import syntax which is standard compliant and brings Angular close to the open web platform.
You also need to be aware of the following issues when upgrading your project:
Angular 8 makes use of the latest TypeScript 3.4, so even if the upgrade process completes with success you might have some syntax errors that may be due to the better type inference system used by the latest version which detects new potential typing issues but in the end this will improve your code quality and helps you avoid bugs in the future. You can see the new features of TypeScript 3.4 from the official docs.
You need to have Node.js 12+. Simply run node -v to verify your Node version. You can install the latest version from the official website

nodejs 4.2.6 not getting updated to latest version

I installed Node and npm as they are required to install angular cli.
Now, if I type this command:
npm install -g angular-cli
I get this message in terminal:
ERROR: npm is known not to run on Node.js v4.2.6 Node.js 4 is supported but the specific version you're running has a bug known to break npm. Please update to at least 4.7.0 to use this version of npm. You can find the latest release of Node.js at https://nodejs.org/
I also followed this link, but still the issue is not resolved.
I tried removing node, npm and then reinstalling, updating node according to all the ways I found on internet, but still the version(4.2.6) is same.
I don't understand what I am doing wrong as I am new to Linux.
Surprisingly, npm is quite complicated in Linux, until you discover Node Version Manager which allows you to easily install new versions and swap between them.
After installing nvm, you can install any node version with nvm install <VERSION_NUMBER> and you can set it as default with nvm alias default <VERSION_NUMBER>
You can swap between versions using nvm use <VERSION_NUMBER>

An asset cannot be written to a location outside the project - angular cli

I'm totaly confused right now. I'm not able to use ng serve anymore since i upgraded the Angular-CLI to > 1.5.3 because of the error i get:
An asset cannot be written to a location outside the project
So i tried to do a downgrade, i did it like this:
npm uninstall -g #angular/cli
npm uninstall -g angular-cli
npm cache clean --force
restarted windows pc
npm install -g #angular/cli#1.5.3
i did this three times and everytime i check which version is installed after i reinstalled the cli, it is 1.5.4 - i'm realy angry about this and don't know, what i'm doing wrong.
It's a known error in Versions higher than 1.5.3, you can have a look at it over here https://github.com/angular/angular-cli/issues/8613
so please, how can i install and use angular-cli at version 1.5.3
Please note, you may manually Copy node_modules\ng2-pdfjs-viewer\pdfjs to your public or asset folder or use any copy script as part of your build process.
Worked for me
Have you seen https://www.npmjs.com/package/ng2-pdfjs-viewer#step-2-copy-task-for-pdfjs

Resources