No solution, I still have this : "ng : command not found" [closed] - node.js

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
so far I managed to run ng serve, but since 4 or 5 days I can not, to solve the problem I tried everything that is proposed as a solution on the net but nothing works...
That's why I sincerely need your help !
How can I refurbish everything to make sure it will work ?
package.json :
{
"name": "cli-src",
"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/common": "^4.0.0",
"#angular/compiler": "^4.0.0",
"#angular/core": "^4.0.0",
"#angular/forms": "^4.0.0",
"#angular/http": "^4.0.0",
"#angular/platform-browser": "^4.0.0",
"#angular/platform-browser-dynamic": "^4.0.0",
"#angular/router": "^4.0.0",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"#angular/cli": "1.0.0",
"#angular/compiler-cli": "^4.0.0",
"#types/jasmine": "2.5.38",
"#types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^0.2.0",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0"
}
}
For info, I'm on WINDOWS.
Thank you very much who will try to help me !

1) Ensure that you have the Angular cli installed by typing this at the command line: ng -v
2) Ensure you are in the folder containing the package.json file. To confirm, navigate to the folder you are using and list the files.
3) Open the package.json file and ensure it has a scripts section with the appropriate scripts defined.
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
4) Ensure you have installed all of the packages for the application. To confirm, ensure that there is a node_modules folder at the same location as the package.json file. To be absolutely sure, navigate to the folder containing the package.json file and type npm install.

This appears to be an issue using Bash. Consider NOT using Bash with windows. (I don't).
If you need to continue to use Bash, see the extended set of information here: https://github.com/angular/angular-cli/issues/5021
If you are on Windows:
1) Right-click on the start button in the lower left corner and select Run.
2) Select to open cmd, which may already be the default.
3) Click OK. This should open a command prompt.
4) Type the commands specified earlier, one at a time:
npm uninstall #angular/cli -g
npm cache --force clean
npm install #angular/cli -g
5) Type ng -v and you should now have the CLI appropriately installed.

Related

AngularJs CLI An unhandled exception occurred:catch clause variable is not an Error instance, while creating angular component using ng g c my-compnnt

Getting below error while creating component using ng g c my-component
'An unhandled exception occurred: catch clause variable is not an Error instance
See "path-to-file\angular-errors.log" for further details.'
And file contains below stack trace:
[error] AssertionError [ERR_ASSERTION]: catch clause variable is not an Error instance
at assertIsError (C:\Users\sam\node_modules#angular\cli\src\utilities\error.js:16:26)
at GenerateCommandModule.runSchematic (C:\Users\sam\node_modules#angular\cli\src\command-builder\schematics-command-module.js:311:43)
at async GenerateCommandModule.handler (C:\Users\sam\node_modules#angular\cli\src\command-builder\command-module.js:109:24)
No luck even after updating angular cli
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
npm cache verify
npm install -g #angular/cli#latest
below is my package.json file:
{
"name": "my-sample-frontend",
"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": "^14.1.0",
"#angular/common": "^14.1.0",
"#angular/compiler": "^14.1.0",
"#angular/core": "^14.1.0",
"#angular/forms": "^14.1.0",
"#angular/platform-browser": "^14.1.0",
"#angular/platform-browser-dynamic": "^14.1.0",
"#angular/router": "^14.1.0",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"#angular-devkit/build-angular": "^14.1.0",
"#angular/cli": "~14.1.0",
"#angular/compiler-cli": "^14.1.0",
"#types/jasmine": "~4.0.0",
"jasmine-core": "~4.2.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.0.0",
"typescript": "~4.7.2"
}
}
The issue is most likely due to the fact that you have two modules in src/app.
So when you try to generate the component, the angular cli does not know where to register this new component.
And that is why the --skip-import option was a workaround for the issue.
However the proper way to handle this would be specifying the module in the ng g c something like this:
ng g c my-component --module=app.module
And the problem is not happening anymore and you register your component in the module as it is intended
Yesterday i had the same problems. I still don`t know why this happen. But when I use --skip-import as parameter the command is running without any errors.
example:
ng g c modules/bla/component/test --skip-import
This will create a new component with the name test in the folder modules/bla/component (relative to the current path) and skip all the imports in the closest module.
Don`t forget to add the component in the declations array in the linked module file.
I had the same issue.
I found that if the file is named with dots it gives error, for example:
src/app/application.material.module.ts
or
src/app/application-material.module.ts
If you change the name to src/app/application-material-module.ts it works.
Regards!
I want to leave my testimony because I had the same problem. the error occurred to me when I tried to better organize the code, in detail I moved the app.component files to a folder (and I updated the dependencies).
these are the files that have undergone a change between the last commit in which I don't have the problem and the first commit in which I have it
I tried your command it's working for me.
Please check your path where you fire this command: ng g c my-component
ADD THE MODULE FLAG (--module=app) TO THE COMMAND
ng g c test2 --module=app

npm error - Cannot find module './selenium-webdriver/lib/input'

After I updated my Angular project's version from 5 to 7, I was getting a lot of vulnerabilities, to fix it - I ran all the commands that was suggested in the "npm audit" and all the vulnerabilities was fixed.
But now when I run:
ng serve
I get this error:
ERROR in node_modules/protractor/built/ptor.d.ts(33,17): error TS2307: Cannot find module './selenium-webdriver/lib/input'.
Edit
If I get in to the errors sources I can see the problem line:
// node_modules/protractor/built/ptor.d.ts
Key: import("./selenium-webdriver/lib/input").IKey;
and if I change the line to:
Key: import("../../selenium-webdriver/lib/input").IKey;
it's fix the error.
I guess it's a versions issue, but now remains to find out what the correct versions.
This is my package.json file:
{
"name": "test",
"version": "1.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-devkit/core": "7.3.6",
"#angular/animations": "7.2.11",
"#angular/common": "7.2.11",
"#angular/compiler": "7.2.11",
"#angular/core": "7.2.11",
"#angular/forms": "7.2.11",
"#angular/http": "7.2.11",
"#angular/platform-browser": "7.2.11",
"#angular/platform-browser-dynamic": "7.2.11",
"#angular/router": "7.2.11",
"core-js": "^2.4.1",
"rxjs": "^6.4.0",
"selenium-webdriver": "^4.0.0-alpha.1",
"tslib": "^1.9.0",
"zone.js": "^0.8.29"
},
"devDependencies": {
"#angular-devkit/build-angular": "^0.13.7",
"#angular/cli": "7.3.6",
"#angular/compiler-cli": "7.2.11",
"#angular/language-service": "7.2.11",
"#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": "^4.0.1",
"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": "^6.0.0",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "3.2.4"
},
"description": "This project was generated with [Angular CLI]
(https://github.com/angular/angular-cli) version 1.6.3.",
"main": "/",
"repository": {
"type": "git",
"url": "/"
},
"keywords": [
"/"
],
"author": "/"
}
Any ideas why?
To resolve this issue I had to run this command:
npm install protractor#latest --save
This error comes when you import from 'protactor' rather than '#angular/platform-browser' in your test cases.
It looks like the problem is with the package with #types:
https://github.com/angular/protractor/issues/5192
Maybe try use previous version for example: #types/selenium-webdriver#2.53.33
Backup your code including node_modules folder
Remove node_modules folder and package-lock.json file
Run the following command in root folder of the application
npm i
ng serve
Can you try these two commands in terminal to ensure that all the packages are installed:
npm i selenium-webdriver --save and npm i
which is also same as
npm install selenium-webdriver --save and npm install
I've got the same error. It is only happened because somehow I added the following line to one of my controller.ts file:
import { element } from 'protractor';
After I removed that line, the problem was solved.
If this happens suddenly after saving your code and you are using visual studio code:
Search for protractor and consider checking your created typescript files for unused imports.
You can delete them using alt+shift+o
Save your files and run ng serve, this should solve your problem
just run
npm install
then
ng serve
it worked for me :)

How to configure angular 2/4 using current user profile (guest or privilege access role) locally

Issues to install ng command. I am trying to install for completely offline admin access privilege environment.
I have configured angularjs 1.5 environment using current user profile and working fine. I don't have admin right. I need to use proxy as well to serve npm. I am using gulp for angular project 1.x. I have setup environment variable for current user.
I am trying to install #angular/cli. It is not working.
I am using node version: 7.0.0 and npm version: 3.6.2
I think python is okay.
C:\Users\xxxxxx>python
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (
AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
You can see the image, Node was installed inside: C:\Node.js using msiexec /a node-v7.0.0-x64.msi /qb TARGETDIR="C:\Node.js". I also tried by changing it to C:\Users\xxxx\Node.js along with environment variable and removed C:\Node.js. It still doesn't work.
Here is error message. There is nothing in .log. Left is for npm install #angular/cli and right is for npm install package.json
enter image description here
Here is package.json
"name": "user-ui",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --host 'abc.com' --port 4200",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "^4.0.0",
"#angular/common": "^4.0.0",
"#angular/compiler": "^4.0.0",
"#angular/core": "^4.0.0",
"#angular/forms": "^4.0.0",
"#angular/http": "^4.0.0",
"#angular/platform-browser": "^4.0.0",
"#angular/platform-browser-dynamic": "^4.0.0",
"#angular/router": "^4.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.4.1",
"zone.js": "^0.8.14"
},
"devDependencies": {
"#angular/cli": "1.2.6",
"#angular/compiler-cli": "^4.0.0",
"#angular/language-service": "^4.0.0",
"#types/jasmine": "~2.5.53",
"#types/jasminewd2": "~2.0.2",
"#types/node": "~7.0.0",
"codelyzer": "~3.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.0.4",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
}
}

npm install is building .cmd files in my angular project root directory

I have a project that I've been working with for quite some time and it has built and compiled (and still does on a different machine) for months. Now, when I run the command npm install it runs as normal, but at the end of the process, it builds out tons of .cmd files (and another accompanying file) in the root folder of my project.
when I run ng serve i get the error:
Unknown browser query basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
I'm completely stumped as to how to get my project back to a usable and buildable state. Have never had problems with my angular builds like this. Also my package.json file is below.
{
"name": "project",
"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/cli": "1.0.0",
"#angular/compiler-cli": "^4.0.0",
"#angular/animations": "^4.0.1",
"#angular/common": "^4.0.0",
"#angular/compiler": "^4.0.0",
"#angular/core": "^4.0.0",
"#angular/forms": "^4.0.0",
"#angular/http": "^4.0.0",
"#angular/platform-browser": "^4.0.0",
"#angular/platform-browser-dynamic": "^4.0.0",
"#angular/router": "^4.0.0",
"angular2-notifications": "^0.7.4",
"core-js": "^2.4.1",
"pdfmake": "^0.1.28",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"#types/jasmine": "2.5.38",
"#types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^0.2.0",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0"
}
}
I face the same issue after changing my laptop domain and create a new user profile.
These files should be generated under node_modules/.bin folder.
As a workaround, you can delete these files manually after each time you run npm install then run ng serve you should not see errors.
Another information from here
It looks like the contents of your node_modules/.bin/ folder are
entirely pushed to your root folder. It might have to do with
something installed on your computer, a config of npm or an antivirus.

Deploying angular 2 App (angular cli) to heroku

I built and angular 2 app with angular cli
ng build command works totally fine, it creates the dist folder.
In order to deploy it I followed this tutorial
Deploy angular 2 app to heroku
When I follow all the steps, I type heroku open but I get an app error
ng: not found
log
here is my package.json file if you want to see it
It seems that is problem of angular-cli and his command ng
but here in my package.json i have it
`{
"name": "rusticstock",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "http-server",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor",
"preinstall": "npm install -g http-server",
"postinstall": "ng build && mv dist/* ."
},
"private": true,
"dependencies": {
"angular-cli": "1.0.0-beta.16",
"#angular/common": "2.0.2",
"#angular/compiler": "2.0.2",
"#angular/core": "2.0.2",
"#angular/forms": "2.0.0",
"#angular/http": "2.0.0",
"#angular/platform-browser": "2.0.2",
"#angular/platform-browser-dynamic": "2.0.2",
"#angular/router": "3.0.0",
"core-js": "^2.4.1",
"bootstrap": "^3.3.6",
"ng2-bs3-modal": "^0.10.4",
"rxjs": "5.0.0-beta.12",
"ts-helpers": "^1.1.1",
"zone.js": "^0.6.23",
"#types/jasmine": "^2.2.30",`enter code here`
"codelyzer": "~0.0.26",
"jasmine-core": "2.4.1",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "4.0.9",
"ts-node": "1.2.1",
"tslint": "3.13.0",
"typescript": "2.0.2"
},
"devDependencies": {
},
"engines": {
"node": "6.6.0",
"npm": "3.10.3"
}
}
`
One more thing, when I'm deploying I see installing components like #angular/common ... but no all of them.
any suggestion would be appreciated.
looks like your heroku app instance does not have angular-cli installed.
I found a way to get it installed.
In your package JSON, add preinstall command like this
"scripts": {
"start": "http-server",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor",
"preinstall": "npm install -g angular-cli",
"postinstall": "ng build && mv dist/* ."
},
This will get angular-cli installed on heroku server and you will not get ng command not found related errors.
While "git push heroku master" is going on, heroku runs the package.json file.
By default, however, Heroku will only install the packages listed in the dependencies object and will ignore those in devDependencies. Since we want the application build step to take place on the server rather than on our local machine, we need to adjust the package.json file a bit.
Angular CLI apps put the #angular/cli module itself as a dev dependency, meaning that we won't be able to access any ng commands on the server. To get around this, we need to move it to dependencies.
// package.json
"dependencies": {
// ...
"#angular/cli": "7.3.9",
},
My problem was that I was working in another branch and heroku only was taking the progress made in the master branch

Resources