简体   繁体   English

在package.json中包含依赖项时遇到麻烦

[英]Having trouble including a dependancy in package.json

I have an angular project (really just the docs tutorial ) and I want to include the node-mysql module in my project- doesn't have to be installed globally. 我有一个角度项目(实际上只是docs tutorial ),并且我想在我的项目中包含node-mysql模块-不必全局安装。

Not sure I understand how this works but I thought all I have to do was add this module to package.json as a dependency and run npm install, but I get an error: 不知道我了解这是如何工作的,但是我想我所要做的就是将此模块作为依赖项添加到package.json并运行npm install,但是出现错误:

    PS> cat .\package.json
    {
      "version": "0.0.0",
      "private": true,
      "name": "angular-phonecat",
       ...
      "dependencies": {
        "node-mysql": ">=2.5.0"
      },
      "devDependencies": {
        "karma": "^0.12.16",
       ...

The error: 错误:

PS> npm install
npm WARN package.json karma-chrome-launcher@0.1.7 No README data
npm ERR! notarget No compatible version found: node-mysql@'>=2.5.0'
npm ERR! notarget Valid install targets:
npm ERR! notarget ["0.1.1","0.1.2","0.1.3","0.1.4","0.1.5","0.1.6","0.1.7","0.1.8","0.1.9","0.2.0","0.2.1","0.2.2","0.2.3","0.2.4","0.2.5","0.2.6","0.2.7","0.2.8","0.2.9","0.3.0","0.3.1","0.3.2","0.3.3","0.3.4","0.3.5","0.3.6","0.3.7","0.3.8","0.3.9","0.4.0","0.4.1"]
npm ERR! notarget
npm ERR! notarget This is most likely not a problem with npm itself.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd C:\testangular\ticketsys\angular-phonecat
npm ERR! node -v v0.10.32
npm ERR! npm -v 1.4.28
npm ERR! code ETARGET
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\testangular\ticketsys\angular-phonecat\npm-debug.log
npm ERR! not ok code 0

How can I include this dependency in my project? 如何在项目中包含此依赖项?

Node-mysql version >2.5 is not out yet. Node-mysql版本> 2.5尚未发布。 Node-mysql is on version 0.4.1. Node-mysql版本为0.4.1。 I suspect you are looking for just the regular mysql npm module. 我怀疑您只是在寻找常规的mysql npm模块。 Mysql on npm is on version 2.5.4. npm上的MySQL版本为2.5.4。

Try using this instead: 尝试使用此代替:

"mysql": ">=2.5.0"

If you go to this page: https://github.com/felixge/node-mysql . 如果转到此页面: https : //github.com/felixge/node-mysql They say in the install instructions to use npm install mysql. 他们在安装说明中说要使用npm install mysql。 This might be a bit confusing since their github page is node-mysql. 这可能有点令人困惑,因为他们的github页面是node-mysql。

Alternatively instead of adding this manually to the dependency you could go ahead and do the following: 另外,也可以手动执行以下操作,而不是手动将其添加到依赖项中:

npm install mysql --save 

This will only install the most up to date one locally (Not globally, if you wanted to install it globally you could add the -g flag, but since you don't need that dont!). 这只会在本地安装最新版本(不是全局安装,如果要在全局安装,则可以添加-g标志,但由于不需要那么做!)。

As mentioned in other answers, npm is not recognizing the version you have specified. 如其他答案中所述,npm无法识别您指定的版本。 I would recommend removing that line from your package.json and instead running a single command: 我建议从您的package.json中删除该行,而不是运行一个命令:

npm install --save mysql

This will install the dependency locally AND add the line to your package.json(that's what the --save flag does). 这将在本地安装依赖项,并将该行添加到package.json(这是--save标志的作用)。 This automatically defaults to the most recent stable version of node-mysql. 这将自动默认为node-mysql的最新稳定版本。

In general, the only time you'll want to specify an actual version in your package.json is if a library patched over some features you actually wanted, in which case you could specify a version so that the necessary features are always there. 通常,唯一一次要在package.json中指定实际版本的情况是,如果库在您实际需要的某些功能上打了补丁,在这种情况下,您可以指定一个版本,以便始终存在必要的功能。 So definitely start using the --save flag when you can. 因此,请尽可能地开始使用--save标志。 It's super useful. 超级有用。 Best of luck! 祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM