Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can anyone explain this error when I run "npm run ng new app"?

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

like image 986
Jodast Avatar asked Sep 10 '18 20:09

Jodast


People also ask

What is difference between npm and Ng?

NPM is basically a package manager which acts as a dependency provider. If there are many small packages, required to build a large one, NPM is the one hotspot which will provide us with the packages. Angular-CLI is one of those packages. As far as NG is concerned, it is the core module of Angular.

What does npm run actually do?

npm run sets the NODE environment variable to the node executable with which npm is executed. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install , just in case you've forgotten.

Is npm start same as NG serve?

npm start runs an arbitrary command specified in the package's "start" property of its "scripts" object. If no "start" property is specified on the "scripts" object, it will run node server. js. It seems like ng serve starts the embedded server whereas npm start starts the Node servers.


1 Answers

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.

like image 134
frosty Avatar answered Sep 30 '22 03:09

frosty