npm install 给出错误“找不到 package.json 文件"; [英] npm install gives error "can't find a package.json file"

查看:222
本文介绍了npm install 给出错误“找不到 package.json 文件";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

npm install/npm install -g 命令在 Windows 7 中不起作用

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

Node.js 安装正确,node.js 版本为 v0.10.28

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

无法读取依赖项
ENOENT,打开文件路径"\package.json'
这很可能不是 npm 本身的问题.
npm 在您的当前目录中找不到 package.json 文件.

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.

推荐答案

你没有说你想安装什么模块 - 因此 npm 寻找一个描述你的依赖项的文件 package.json,显然这个文件丢失了.

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.

所以要么你必须明确告诉 npm 要安装哪个模块,例如

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

npm install express

npm install -g express-generator

或者您必须添加一个 package.json 文件并在此处注册您的模块.获取这样一个文件的最简单方法是让 npm 通过运行创建一个

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"
  }
}

或者类似的东西.有关 package.json 文件的更多信息,请参阅其官方文档本互动指南.

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

这篇关于npm install 给出错误“找不到 package.json 文件";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆