4
votes

So I'm trying to make a new angular app for the first time, and I installed it using npm i -g @angular/cli. When I try to make a new app using npm run ng new app, it gives me this error:

npm ERR! path E:\ddii\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'E:\ddii\package.json'
npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users...\AppData\Roaming\npm-cache_logs\2018-09-10T20_22_50_118Z-debug.log

enter image description here enter image description here

4
I think the command is ‚ng new <project name>‘ instead of yours. Can you try that?kedenk
@kedenk It said ng not recognizedJodast
Why don't you use "ng new project_name" instead of "npm run ng new app"Raj
@Raj when I ran ng new project_name it said 'ng is not an internal or external command'Jodast
Please add a screenshot.....and check cmd path where you hit the command...either you don't have angular cli installed or you are in the wrong folderRaj

4 Answers

3
votes

In short, you are running the command incorrectly. Remove the npm run from the front of your command, and it should work.

When you say npm run blah, npm does a lookup in your package.json for a script called blah or in your case ng. So... if you are running npm run ng new app, npm wants there to be a package.json in your current directory, and in that package.json, npm expect a script called ng. So if you don't have a package.json in your current dir, then you are going to get an error.

Instead, close your terminal, and open a new terminal and run simply ng new app.

2
votes

If you want to run it without the npm run ..., you need to install ng globally, I would do npm install -g @angular/cli, however I'm running linux, for windows I've found this thread ng is not recognized as an internal or external command

It should help you install a global version of angular-cli, you'll basically do two things:

  1. Install globally angular-cli (if you don't have it).
  2. Make sure it's in your environment variable's PATH.

Check the question answers, details are there.

2
votes

Could help for future references

At least for me this work. Sometimes, the reference to the file ng.cmd (in case of Win users) is not well formed and you have to call it and pass the arguments directly

e.g.

< path-where-ng.cmd-file-is-located >\ng.cmd new app

Running calling ng.cmd file directly

It says: ' "ng" is not recognized as an internal or external command, operable program or batch file.'

And it works even if you do not have admin permissions for any reason

0
votes

I struggled to find this answer myself, as the other answers on this question do not address the real underlying issue.

All the other answers suggest to install ng GLOBALLY using (npm i -g ...), with the side effect that a symlink to ng will be on your PATH.

Based on OP's question, I do concede he was most likely attempting to scaffold a new Angular app from the GLOBALLY installed ng. So this handles 90% of people's questions, and is all fine and nice.

I, however, want to use the LOCALLY INSTALLED ng, which is why I have an npm-script in my package.json for it:

{
...
  "scripts": {
...
    "ng": "ng",
...
}

If this describes your use case like it does mine, then read on.

npm run ng update succeeds for me, whereas other more complex commands with more arguments—including command-line switches—fail outright (npm run ng -- update @angular/cli --migrate-only tslint-version-6).

The answer lies in that you must delimit the start of arguments being passed to npm run-script with -- (see https://stackoverflow.com/a/14404223/1438576):

npm run ng -- update @angular/cli --migrate-only tslint-version-6

So in OP's case, assuming he already had a locally-installed copy of ng with a package.json (which I admit is doubtful), he could have done:

npm run ng -- new app

Anyway, hope this helps others.