After a months-long interruption of a web development project with WSL2 (VS code), I refreshed all the tools with
*npm i -g npm-check-updates, ncu -u, npm install*
I got the version @angular/core@"~15.0.4. But due to an incompatibility with the latest version of another tool, I wanted to go back to the v14:
*ng update @angular/core@14 @angular/cli@14*
Unfortunately, since then, every time I try to run
ng something (serve, version…),
an unusable text editor opens in the terminal with a white footing banner : « ---Mg: scratch (fundamental)----All----------------- », and a button « ng-latin » on the side, which shows « shell integration activated » on click.
I then followed this advice from https://www.declarecode.com/code-solutions/shell/mg-scratch-fundamental-all:
sudo apt remove mg ng-common
Launching
ng...,
the following message was displayed in the console:
Command 'ng' not found, but can be installed with: sudo apt install ng-common
But then I always fall back on the text editor with « ---Mg: scratch [or serve] (fundamental)----All----------------- »
Besides, I don't understand why it’s not possible to upgrade Angular by skipping major versions, as I did by mistake. But perhaps I see the consequence through this blockage.
I can't use the command ng anymore with WSL2.
How can I get out of this trap ?
CodePudding user response:
When you type ng
in your terminal, Linux (WSL2) tries to find the corresponding binary on your file system.
If you run this without any installation, indeed, it will prompt you to install ng-common. THIS IS NOT ANGULAR. (I don't even know what it is to be honest).
What you need to do is install the Angular CLI. To do that, you have to use NPM.
If you wish to type ng
directly in the console, then you need it installed globally. I wouldn't recommend this approach, but I'll give you the solution for this anyway :
npm i -g @angular/cli@14
After that, your ng
command should work.
Second solution, which is the simplest one, is to use npm to run the command.
In case you don't know, when your run npm run XXX
, NPM will look for the corrsponding binary in your node_modules folder. So if you have the CLI installed in your project, you can run this :
npm run ng -- version
This works because in your package.json, you have a script called ng
. Note the space between the --
and version
: this is how you project parameters to a NPM command. Don't forget this space !
The last method, which is my preferred one, is using npx
. NPX is shipped with NPM and works flawlessly for this kind of issue. I would suggest you learn about it through the documentation, but the gist of it is :
When you're in an angular project folder :
npx ng version
When you're NOT in an Angular project :
npx @angular/cli@14 version
(You can replace the 14 with any version you want)
CodePudding user response:
It seems like the issue might be related to a problem with the mg text editor. You can try uninstalling mg and ng-common using the following command:
sudo apt-get remove mg ng-common
If the package is damaged or corrupted, it may not be possible to remove it. In this case, you can try repairing the package by running sudo apt-get install --reinstall ng-common.
If none of the above solutions work, you can try manually removing the package files from your system. To do this, you can use the find and rm commands to locate and delete the package files.