node.js npm 出现“无法读取依赖项”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18401934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:24:18  来源:igfitidea点击:

"Couldn't read dependencies" error with npm

javascriptjsonnode.jsnpm

提问by dvdmn

I wanted to start a Node app and created a package.jsonfile with a tutorial. Here is the json file:

我想启动一个 Node 应用程序并创建一个带有教程的package.json文件。这是json文件:

{
    "name": "Dashboard",
    "version": "0.0.0",
    "description": "Client-A Dashboard",
    "dependencies": {
        "socket.io": "latest",
        "express": "latest",
        "jade": "latest"
    },
    "author": "tD"
}

I verified JSON file before trying to run it, but still I got an error message when I ran the npm installcommand:

我在尝试运行它之前验证了 JSON 文件,但是当我运行npm install命令时仍然收到一条错误消息:

npm ERR! install Couldn't read dependencies
npm ERR! Error: ENOENT, open 'C:\projects\Client-A\Live\package.json'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\Program Files (x86)\nodejs\\node.exe" "C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js" "install"
npm ERR! cwd C:\projects\Client-A\Live\
npm ERR! node -v v0.8.22
npm ERR! npm -v 1.2.14
npm ERR! path C:\projects\Client-A\Live\package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\projects\Client-A\Live\npm-debug.log
npm ERR! not ok code 0

and here is the npm-degub.logfile

这是npm-deub.log文件

0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files (x86)\nodejs\\node.exe',
1 verbose cli   'C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli   'install' ]
2 info using [email protected]
3 info using [email protected]
4 verbose node symlink C:\Program Files (x86)\nodejs\node.exe
5 verbose read json C:\projects\Client-A\Live\package.json
6 error install Couldn't read dependencies
7 error Error: ENOENT, open 'C:\projects\Client-A\Live\package.json'
8 error If you need help, you may report this log at:
8 error     <http://github.com/isaacs/npm/issues>
8 error or email it to:
8 error     <[email protected]>
9 error System Windows_NT 6.1.7601
10 error command "C:\Program Files (x86)\nodejs\\node.exe" "C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js" "install"
11 error cwd C:\projects\Client-A\Live\scoreboard
12 error node -v v0.8.22
13 error npm -v 1.2.14
14 error path C:\projects\Client-A\Live\package.json
15 error code ENOENT
16 error errno 34
17 verbose exit [ 34, true ]

采纳答案by JorgeArtware

Try to add this:

尝试添加这个:

"private": true,

"private": true,

it worked for me.

它对我有用。

EDIT(for people asking why):

编辑(对于问为什么的人):

The Oficial documentationstates the following:

公报的文件规定如下:



If you set "private": truein your package.json, then npm will refuse to publish it. This is a way to prevent accidental publication of private repositories. If you would like to ensure that a given package is only ever published to a specific registry (for example, an internal registry), then use the publishConfighash described below to override the registryconfig param at publish-time.

如果你"private": true在 package.json 中设置,那么 npm 将拒绝发布它。这是一种防止意外发布私有存储库的方法。如果您想确保给定的包只发布到特定的注册表(例如,内部注册表),请使用publishConfig下面描述的哈希registry在发布时覆盖配置参数。



The error messages you are getting may be related to violating this "rule" in a way (mine was).

您收到的错误消息可能与以某种方式违反此“规则”有关(我的是)。

  • Either you are marking a unpublished package (like your own app) as "private": false.
  • Or you are neglecting to include any value at all.
  • 要么您将未发布的包(如您自己的应用程序)标记为 "private": false.
  • 或者您根本忽略了包含任何值。

回答by Cody

I had an "Invalid Name"

我有一个 "Invalid Name"

I switched from "name": "Some Name",...to "name": "Some-Name",...

我从 切换"name": "Some Name",..."name": "Some-Name",...

Guess nameneeds to be a sluggy string.

Guessname需要是一个懒惰的字符串。

回答by Dmitriy

Recently, I've started to get an error:

最近,我开始收到错误:

npm ERR! install Couldn't read dependencies
npm ERR! Error: Invalid version: "1.0"

So, you may need to specify versionof your package with 3 numbers, e.g. 1.0.0instead of 1.0if you get similar error.

因此,您可能需要version用 3 个数字来指定您的包裹,例如1.0.01.0如果您遇到类似的错误,则不要这样做。

回答by Breno

It's simple, you're just not in the right directory.

很简单,你只是不在正确的目录中。

Go to the C:\Program Files\nodejs\node_modules\npmand you should be able to run this command properly.

转到 C:\Program Files\nodejs\node_modules\npm,您应该能够正确运行此命令。

回答by user1524615

Try to update npm,It works for me

尝试更新 npm,它对我有用

[sudo] npm install -g npm

回答by HADI

I got the same exception also, but it was previously running fine in another machine. Anyway above solution didn't worked for me. What i did to resolve it?

我也遇到了同样的异常,但它以前在另一台机器上运行良好。无论如何,上述解决方案对我不起作用。我做了什么来解决它?

  1. Copy dependencies list into clipboard.
  2. enter "npm init" to create fresh new package.json
  3. Paste the dependencies again back to package.json
  4. run "npm install" again!
  1. 将依赖项列表复制到剪贴板。
  2. 输入“npm init”以创建全新的 package.json
  3. 再次将依赖项粘贴回 package.json
  4. 再次运行“npm install”!

Done :) Hope it helps.

完成:) 希望它有所帮助。

回答by Martin Konecny

My mistake was the I named the file packages.jsoninstead of package.json

我的错误是我命名文件packages.json而不是package.json

回答by Cyril N.

For me it was the version. Yes, the line you put at the root, like :

对我来说是版本。是的,您放在根目录下的行,例如:

{
    "name": "your-project",
    "version": "0.1"
    ...
}

Yes, npm doesn't like version like this, it prefers something like "0.0.1".

是的,npm 不喜欢这样的版本,它更喜欢“ 0.0.1”之类的东西。

Don't ask me why, I'll tell you it's totally stupid (or "how to loose time easily")

不要问我为什么,我会告诉你这完全是愚蠢的(或者“如何轻松地浪费时间”)

回答by Micah Armantrout

I figured out I wasn't in the correct folder. I needed goto the folder I just cloned before I ran this command.

我发现我不在正确的文件夹中。在运行此命令之前,我需要转到刚刚克隆的文件夹。

回答by Tisch

I got this error when I had a space in my "name" within the packagae.json file.

当我在 packagae.json 文件中的“名称”中有一个空格时出现此错误。

"NPM Project" rather than "NPMProject"

“NPM 项目”而不是“NPM 项目”