198

I'm trying to install the dependencies of some example: npm's express 2.5.8 that I've downloaded, but all of the apps throw the same error:

c:\node\stylus>npm install -d
npm info it worked if it ends with ok
npm info using npm@1.1.1
npm info using node@v0.6.11
npm ERR! Couldn't read dependencies.

npm ERR! Error: ENOENT, no such file or directory 'c:\node\stylus\package.json'
npm ERR! You may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>
npm ERR!
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program File
s (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-d"
npm ERR! cwd c:\node\stylus
npm ERR! node -v v0.6.11
npm ERR! npm -v 1.1.1
npm ERR! path c:\node\stylus\package.json
npm ERR! code ENOENT
npm ERR! message ENOENT, no such file or directory 'c:\node\stylus\package.json'

npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     c:\node\stylus\npm-debug.log
npm not ok

The blockage appears to be:

no such file or directory 'c:\node\stylus\package.json

Did I miss a step that creates the package.json ?

I'm running:

  • Windows 7 64 bit
  • npm 1.1.1
  • node 6.11
  • express 2.5.8
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
imjp
  • 6,495
  • 10
  • 48
  • 58
  • How did you download the packages? Can you install them the usual way (i.e. with `npm install `? – Linus Thiel Feb 28 '12 at 15:47
  • I haven't tried that, because I don't know exactly which packages are used in the apps. How can I find this out so I can try installing them manually? – imjp Feb 28 '12 at 15:49
  • 1
    `npm view ` will show you the `package.json` along with the dependencies. Also, `npm help` is your friend. – Linus Thiel Feb 28 '12 at 15:53
  • I've checked out the package file with `npm view package` but I get this error: http://i.imgur.com/AwGHu.gif. I'm trying to get some of these to work: https://github.com/visionmedia/express/tree/2.x/examples – imjp Feb 28 '12 at 15:54
  • 2
    Hmmm... `` was meant as an example. Try e.g. `npm view stylus`. – Linus Thiel Feb 28 '12 at 15:58
  • Look at this error it's throwing regarding package.json module is deprecated: https://gist.github.com/1933333 – imjp Feb 28 '12 at 16:01
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/8313/discussion-between-linus-g-thiel-and-imjp) – Linus Thiel Feb 28 '12 at 16:02
  • use this [solution](https://stackoverflow.com/questions/48224025/npm-behind-a-proxy-with-the-character-in-my-password/50214574#50214574). it worked for me. – saeid mohammad hashem May 07 '18 at 12:59
  • what i did i i upgrade pnpm `pnpm add -g pnpm` then `pnpm i` – Clode Morales Pampanga III Feb 08 '23 at 03:00

29 Answers29

210

I think, npm init will create your missing package.json file. It works for me for the same case.

lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
Deepali Agarwal
  • 2,119
  • 2
  • 9
  • 3
143

In your project's folder, you need to initialize the package.json file by running the following in the terminal:

npm init

After that, you should be able to install any packages as you would expect, like express:

npm install express

Shout out to Deepali's answer.

Aldo
  • 1,677
  • 1
  • 12
  • 15
  • 2
    and where is express if I previously installed with "npm install -g express" ? – sports Jul 17 '14 at 18:12
  • 1
    You need to execute "npm install -g express-generator" with > Express 4.0.0. Source: http://stackoverflow.com/questions/23002448/express-command-not-found , after that the express command can be executed – Lucian Depold Oct 23 '14 at 10:13
  • UBUNTU console suggested `sudo apt install node-express-generator` ... So, what the best, `apt install` or `npm install`? – Peter Krauss Mar 19 '18 at 06:06
89

I'll be brief but deadly. :) install -d will not work for you. It's simple. Try

$ npm install -g express
Zoe Marmara
  • 1,142
  • 1
  • 10
  • 15
  • Not worked, need `sudo npm install -g express` ... Is correct? – Peter Krauss Mar 19 '18 at 06:08
  • > "the -g flag is a shorthand for the global configuration which sets the package install location to the folder where you installed NodeJS." – jsta Mar 03 '22 at 16:22
68

Follwing the below steps you well get package.json file.

npm --version
npm install express
npm init -y
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Elangovan
  • 3,469
  • 4
  • 31
  • 38
19

If Googling "no such file or directory package.json" sent you here, then you might be using a very old version of Node.js

The following page has good instructions of how to easily install the latest stable on many Operating systems and distros:

https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

Gerry
  • 10,584
  • 4
  • 41
  • 49
  • Was using `node --version` 0.10.31 and was having this issue. Downgraded to 0.10.29 and it still wasn't resolved. It seems to be an issue with the Windows installer as they've also ceased creating the `C:\Users\User\AppData\Roaming\npm` folder. – Shawn Solomon Sep 06 '14 at 22:52
  • 8
    I got the "no such file or directory package.json" error trying to run 'npm install' on the Angular.js tutorial and ended up here. It wasn't obvious in the instructions that you need to cd into the checked out code for the tutorial - in this case the package.json is in the dir you cloned from git in the prior step (https://docs.angularjs.org/tutorial) – Kevin Hooke Sep 30 '14 at 21:32
  • 1
    @KevinHooke's solution is the answer for this problem. Running npm -install from the cloned application directory solved the problem. – Vikram May 29 '15 at 16:07
9

Beginners usually try the npm command from random locations. After downloading or creating a project, you have to cd into this project folder. Inside is the file package.json.

cd <path_to_project>
npm install
Matt Montag
  • 7,105
  • 8
  • 41
  • 47
Victor1125
  • 642
  • 5
  • 16
8

Use the command in win7/win8/win10 (CD) for moving folders:

  1. Enter your projects folder

  2. Run: npm install -d

Laurel
  • 5,965
  • 14
  • 31
  • 57
Franklin CI
  • 159
  • 1
  • 9
4

try re-install Node.js

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -

sudo apt-get install -y nodejs

sudo apt-get install -y build-essential

and update npm

curl -L https://npmjs.com/install.sh | sudo sh
lrj
  • 41
  • 2
3

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:

npm -v //The version should be higher than 2.1.8

After this you should be able to run:

npm install
bruntime
  • 371
  • 2
  • 13
2

It may be very evident,
but try to launch CMD (for Windows) from the project folder, where your package.json file is located.

Do not launch CMD from System or from "Search bar" in Win or
move to your project folder with help of cd command and then launch npm start.

rock_walker
  • 453
  • 5
  • 14
2

I had a similar problem with npm. The problem was that I had the project inside two folders of the same name. I resolved it by renaming one of the folders to something else (outer folder recommended).

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
Ashish Kirodian
  • 816
  • 7
  • 13
2

It by itself says that package.json is not available in your project. So, to create package.json, use the following steps:

  1. open command prompt on your project directory
  2. npm init (it will ask you to enter lots of entries like name, version, desc, etc., enter some random values and click enter).
  3. type yes and click enter

Now try again.

Marko Bonaci
  • 5,622
  • 2
  • 34
  • 55
2

Go inside the project folder and check whether the package.json file does exist.

If you are creating the project using Visual Studio Angular project, make sure you run this command inside the ClientApp Folder. there is a good chance, you could be looking for project.json file outside the ClientApp folder.

2

if the package.json file in the project directory is missing then you can create it by npm init.

if the package.json file is already created in the project directory then there is a possibility that you are not running your project from the right path. Use cd your-project-path in the terminal and then run your project from there.

zernab hussain
  • 339
  • 3
  • 6
2
npm init -y 

use this command, it will automatically create package.json file with all your machine information.

Sagansha San
  • 156
  • 1
  • 4
2

I found myself here trying to resolve the same error message:

npm ERR! message ENOENT, no such file or directory 'c:\<some_folder>\package.json'

The error could be due to two reasons:

  1. You do not have the package.json
  2. You have the package.json, but you are running npm start in the wrong folder

To troubleshoot the first cause, you need to create a package.json using:

npm init

To fix the second cause, make sure the folder you are running the npm start command is the same folder as the package.json

EarlyCoder
  • 1,213
  • 2
  • 18
  • 42
2

I was experiencing this identical error and terminal (foolishly, on my part) was in a parent directory instead of the correct one (where package.json was correctly located).

All I did in terminal was cd [insert correct directory name here, overwriting brackets] and that corrected the problem.

Mark Gavagan
  • 878
  • 12
  • 45
1

My issue was I didn't have a package.json file for some reason. After I wget this file into my directory, I was able to run npm install

https://raw.githubusercontent.com/twbs/bootstrap/master/package.json

PolarisUser
  • 719
  • 2
  • 7
  • 18
  • 2
    I know this is old, but I still have to say - this might suppress the specific error, but this is not the right way to deal with this problem. You're pulling down the package.json for Bootstrap, a completely different project from yours. – Sam Hanley Mar 29 '16 at 01:07
1

Thank you! I also tried many options for this. I am also using windows.This command helped and saved my time:

npm install -g npm@lts
bhattraideb
  • 407
  • 7
  • 25
1

ok, try to go to the home "user@user:~$ " (cd + enter key), and npm install -g your your_module.

sergioAJ
  • 11
  • 1
1

just install any package you want with -g

npm install -g express

Nisarg
  • 1,631
  • 6
  • 19
  • 31
prosper1
  • 304
  • 2
  • 9
0

For the following command

sudo npm install react browserify watchify babelify --save-dev

I got same error

saveError ENOENT: no such file or directory, open '/Users/Path/package.json'

But when I run the command

sudo npm install -gd react browserify watchify babelify --save-dev

then no missing file or directory message appeared.

zeeawan
  • 6,667
  • 2
  • 50
  • 56
0

I have run npm install -y to skip the question step for creating the missing file package.json, y means yes

Python Basketball
  • 2,320
  • 3
  • 24
  • 47
0

I was also facing same issue while installing typescript. I just initialized an package.josn file by the following command

npm init -y

And then i installed my typescript

npm install -g -typescript

http://blossomprogramming.blogspot.com/

0

Please check the directory or the folder in which you're installing your new package. This happened to me as well, My whole project was in a subdirectory and I was trying to install in the main directory. After checking the whole thing I found out that I had to install in the subdirectory where my project files and package.json files are located and it's done. Hope this helps...

Jagadish Meghval
  • 199
  • 1
  • 11
0

the previous tips do not pay attention to any change for me. at the end this works for me:

  1. delete the local repo folder
  2. git clone https ... myRebo.git
  3. npm install
  4. npm start

hope it helps somebody

SL5net
  • 2,282
  • 4
  • 28
  • 44
0

I got this error because I was trying:

npm install --save-exact express@4.17.1 cors@2.8.5 express-bearer-token@2.4.0
@okta/jwt-verifier@1.0.0 mongoose@5.6.7

which I got from: https://developer.okta.com/blog/2019/09/11/angular-mongodb

I had to separate the packages and run them one by one. I think the backslash caused problem.

Markus
  • 1,020
  • 14
  • 18
-1

Adding -g before the package name worked for me. Looking for documentation to explain why this works..

Corey Byrum
  • 119
  • 1
  • 3
-1

Generate package.json without having it ask any questions. I ran the below comment in Mac and Windows under the directory that I would like to create package.json and it works

$ npm init -y

Wrote to C:\workspace\package.json:

{
  "name": "workspace",
  "version": "1.0.0",
  "description": "",
  "main": "builder.js",
  "dependencies": {
    "jasmine-spec-reporter": "^4.2.1",
    "selenium-webdriver": "^4.0.0-alpha.5"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
ecamur
  • 99
  • 1
  • 4