npm can't find package.json

2019-01-10 04:19发布

I'm trying to install the dependencies of some example Express apps 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

Does anyone know what might be the root of this problem?
I'm running:

  • Windows 7 64 bit
  • npm 1.1.1
  • node 6.11
  • express 2.5.8

21条回答
一纸荒年 Trace。
2楼-- · 2019-01-10 04:47

Update 2018

This is becoming quite a popular question and my answer (although marked as correct) is no longer valid. Please refer to Deepali's answer below:

npm init

Original Outdated Answer

I think you forgot to setup the directory for express:

express <yourdirectory>

Once you do that you should be able to see a bunch of files, you should then run the command:

npm install -d

Regards.

查看更多
叼着烟拽天下
3楼-- · 2019-01-10 04:48

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.

查看更多
太酷不给撩
4楼-- · 2019-01-10 04:55

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

查看更多
祖国的老花朵
5楼-- · 2019-01-10 04:55

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.

查看更多
▲ chillily
6楼-- · 2019-01-10 04:55

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

查看更多
我想做一个坏孩纸
7楼-- · 2019-01-10 04:57

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

npm --version
npm install express
npm init -y

Link : http://www.codingslover.com/2017/02/npm-node-js-cant-find-packagejson.html

查看更多
登录 后发表回答