npm install gives error "can't find a package.json file"

node.jsNpm

node.js Problem Overview


npm install / npm install -g command is not working in Windows 7

Node.js is installed properly, node.js version is v0.10.28

>Couldn't read dependencies
>ENOENT, open '"filepath"\package.json'
>This is most likely not a problem with npm itself.
>npm can't find a package.json file in your current directory.

Photo

node.js Solutions


Solution 1 - node.js

You don't say what module you want to install - hence npm looks for a file package.json which describes your dependencies, and obviously this file is missing.

So either you have to explicitly tell npm which module to install, e.g.

npm install express

or

npm install -g express-generator

or you have to add a package.json file and register your modules here. The easiest way to get such a file is to let npm create one by running

npm init

and then add what you need. Please note that this does only work for locally installed modules, not for global ones.

A simple example might look like this:

{
  "name": "myapp",
  "version": "0.0.1",
  "dependencies": {
    "express": "4.0.0"
  }
}

or something like that. For more info on the package.json file see its official documentation and this interactive guide.

Solution 2 - node.js

node comes with npm installed so you should have a version of npm, however npm gets updated more frequently than node does, so you'll want to make sure it's the latest version.

sudo npm install npm -g

Test: Run npm -v. The version should be higher than 2.1.8.

npm install

THAT'S IT!

https://www.youtube.com/watch?v=wREima9e6vk

Solution 3 - node.js

I'm not sure what you're trying to do here:

npm install alone in your home directory shouldn't do much -- it's not the root of a node app, so there's nothing to install, since there's no package.json.

There are two possible solutions:

  1. cd to a node app and run npm install there. OR

  2. if you're trying to install something as a command to use in the shell (You don't have a node application), npm install -g packagename. -g flag tells it to install in global namespace.

Solution 4 - node.js

Use below command to create a package.json file.

npm init 
npm init --yes or -y flag

[This method will generate a default package.json using information extracted from the current directory.]

Working with package.json

Solution 5 - node.js

>> For Visual Studio Users using Package Manager Console <<

If you are using the Package Manager Console in Visual Studio and you want to execute:

npm install and get:

> ENOENT: no such file or directory, open > 'C:\Users...\YourProject\package.json'

Verify that you are executing the command in the correct directory.

VS by default uses the solution folder when opening the Package Manager Console.

Execute dir then you can see in which folder you currently are. Most probably in the solution folder, that's why you get this error. Now you have to cd to your project folder.

cd YourWebProject

Now npm install should work now, if not, then you have another issue.

Solution 6 - node.js

In my case I was trying to create workspace in D drive whereas global packages (node_modules) and package.json was in C. Just had to do

npm install npm@latest -g

Obviously with administrator rights.

After that restart your cmd/terminal. You should be good to go

Solution 7 - node.js

Check this link for steps on how to install express.js for your application locally.

But, if for some reason you are installing express globally, make sure the directory you are in is the directory where Node is installed. On my Windows 10, package.json is located at

C:\Program Files\nodejs\node_modules\npm

Open command prompt as administrator and change your directory to the location where your package.json is located.

Then issue the install command.

Solution 8 - node.js

In my case there was mistake in my package.json:

npm ERR! package.json must be actual JSON, not just JavaScript.

Solution 9 - node.js

I was facing the same issue as below.

> npm ERR! errno -4058 npm ERR! syscall open npm ERR! enoent ENOENT: no > such file or directory, open > 'D:\SVenu\FullStackDevelopment\Angular\Angular2_Splitter_CodeSkeleton\CodeSke > leton\run\package.json' npm ERR! enoent This is related to npm not > being able to find a file. npm ERR! enoent

The problem I made was, I was running the command npm build run instead of running npm run build.

Just sharing to help someone who does small mistakes like me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSubhajit PanjaView Question on Stackoverflow
Solution 1 - node.jsGolo RodenView Answer on Stackoverflow
Solution 2 - node.jsCosimo de' MediciView Answer on Stackoverflow
Solution 3 - node.jsNerveView Answer on Stackoverflow
Solution 4 - node.jskrish007View Answer on Stackoverflow
Solution 5 - node.jsLegendsView Answer on Stackoverflow
Solution 6 - node.jsAdeel ShekhaniView Answer on Stackoverflow
Solution 7 - node.jsVikasView Answer on Stackoverflow
Solution 8 - node.jsOlexandr PolishchukView Answer on Stackoverflow
Solution 9 - node.jsSibeesh VenuView Answer on Stackoverflow