Reputation: 1299
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! enoentnpm 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
Upvotes: 6
Views: 17342
Reputation: 1699
I am not able to change the environmental settings to add ng globally. This is how I created a new angular project using the terminal to run these 4 commands
Step 1.
init
Step 2.
npm i @angular/cli --save-dev
Step 3 - don't skip this step
cd..
Step 4.
c:/code/angular15project/node_modules/.bin/ng new myAngular15project
Upvotes: 0
Reputation: 130
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.
Upvotes: 6
Reputation: 21
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
And it works even if you do not have admin permissions for any reason
Upvotes: 2
Reputation: 267
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:
Check the question answers, details are there.
Upvotes: 2
Reputation: 21762
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
.
Upvotes: 5