2

我是nodejs的新手。我试图按照文档安装nodejs。在使用 npm install 命令安装依赖项时,我遇到了一个错误。

C:\Program Files\nodejs>npm install
npm ERR! install Couldn't read dependencies
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v4.3.1
npm ERR! npm  v2.14.12
npm ERR! path C:\Program Files\nodejs\package.json
npm ERR! code ENOPACKAGEJSON
npm ERR! errno -4058
npm ERR! syscall open

npm ERR! package.json ENOENT: no such file or directory, open 'C:\Program Files\
nodejs\package.json'
npm ERR! package.json This is most likely not a problem with npm itself.
npm ERR! package.json npm can't find a package.json file in your current directo
ry.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Program Files\nodejs\npm-debug.log

C:\Program Files\nodejs>

在 package.json 文件所在的文件夹中运行 npm install 命令后,会出现以下错误:

C:\Program Files\nodejs>npm install
npm ERR! install Couldn't read dependencies
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v4.3.1
npm ERR! npm  v2.14.12
npm ERR! path C:\Program Files\nodejs\package.json
npm ERR! code ENOPACKAGEJSON
npm ERR! errno -4058
npm ERR! syscall open

npm ERR! package.json ENOENT: no such file or directory, open 'C:\Program Files\
nodejs\package.json'
npm ERR! package.json This is most likely not a problem with npm itself.
npm ERR! package.json npm can't find a package.json file in your current directo
ry.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Program Files\nodejs\npm-debug.log

C:\Program Files\nodejs>

npm-debug 日志文件的链接.. 任何帮助将不胜感激..谢谢..

4

5 回答 5

2

要安装依赖项,节点会在项目的根目录中查找一个名为 的文件package.json,其中包含项目所需的所有依赖项的列表。它的内容看起来像这样

听起来您package.json在项目的根目录中丢失了。

要安装依赖项,您通常运行类似的命令

npm install NAMEOFTHEDEPENDENCY --save-dev

grunt-contrib-sass例如,NAMEOFTHEDEPENDENCY 可能是

这也会自动更新您的package.json

于 2016-02-20T15:18:27.690 回答
1

安装 nodejs 后尝试关闭代码编辑器,重新打开并在 package.json 文件所在的同一目录中运行 npm install,忘了提,你是从https://nodejs.org/en/download/安装 nodejs吗?,这是第一个部分。

于 2020-03-09T11:59:39.873 回答
0

从...开始

npm init

这将创建 package.json 文件(您将被要求提供一些数据来填充它)。然后npm intall <package> [--save|saveDev]将正常工作。

于 2020-03-09T12:59:45.817 回答
0

为了npm install工作,您需要与 package.json 文件位于同一目录中。npm install然后查看 package.json 并在那里安装所有依赖项。

https://docs.npmjs.com/files/package.json

https://docs.npmjs.com/getting-started/installing-npm-packages-locally

于 2016-02-20T15:16:27.740 回答
0

您正在 nodejs 文件夹中运行 npm install ,您应该在项目文件夹中运行它。只需确保 npm 在您的路径中。

于 2016-02-20T15:16:49.823 回答