npm找不到package.json

imj*_*mjp 135 node.js npm express

我正在尝试安装我已下载的一些示例Express应用程序的依赖项,但所有应用程序都抛出相同的错误:

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
Run Code Online (Sandbox Code Playgroud)

有谁知道这个问题的根源是什么?
我在跑:

  • Windows 7 64位
  • npm 1.1.1
  • 节点6.11
  • 表达2.5.8

小智 134

我想,npm init会创建你丢失的package.json文件.对于同样的情况,它适用于我.


小智 81

我会简短而致命.:) install -d不适合你.这很简单.尝试

$ npm install -g express
Run Code Online (Sandbox Code Playgroud)

  • 这也为我解决了这个问题,你能解释一下将`express`添加到命令`npm install -g`中可能导致突然改变成功的原因吗?谢谢! (3认同)

Ald*_*ldo 68

更新2018年

这已成为一个非常受欢迎的问题,我的回答(虽然标记为正确)已不再有效.请参阅下面的Deepali的答案:

npm init
Run Code Online (Sandbox Code Playgroud)

原始过时的答案

我想你忘了设置express的目录:

express <yourdirectory>
Run Code Online (Sandbox Code Playgroud)

一旦你这样做,你应该能够看到一堆文件,然后你应该运行命令:

npm install -d
Run Code Online (Sandbox Code Playgroud)

问候.

  • 如果我之前安装了"npm install -g express",那么表达在哪里? (2认同)

Ela*_*van 57

完成以下步骤,您将获得package.json文件.

npm --version
npm install express
npm init -y
Run Code Online (Sandbox Code Playgroud)

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


Ger*_*rry 16

如果谷歌搜索"没有这样的文件或目录package.json"发送到这里,那么你可能正在使用一个非常旧版本的Node.js

以下页面提供了如何在许多操作系统和发行版上轻松安装最新稳定版的良好说明:

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

  • 我得到了"没有这样的文件或目录package.json"错误试图在Angular.js教程上运行'npm install'并最终在这里.在指令中并不明显你需要cd到教程的签出代码 - 在这种情况下,package.json位于你在前一步骤中从git克隆的目录中(https://docs.angularjs.组织/教程) (7认同)

小智 6

使用win7/win8/win10(CD)中的命令移动文件夹:

  1. 输入您的项目文件夹

  2. 跑: npm install -d


Vic*_*125 6

初学者通常从随机位置尝试 npm 命令。下载或创建项目后,您必须 cd 到此项目文件夹中。里面是 package.json 文件。

cd <path_to_project>
npm install
Run Code Online (Sandbox Code Playgroud)