简体   繁体   English

在package.json中包含依赖项的问题

[英]problems with including dependencies in package.json

Why is it that when including dependencies in package.json such as 为什么在package.json中包含依赖项时(例如)

"dependencies": {
    "nodemailer": "*"
 }

and running 并运行

npm install

doesn't install the package but doing 不安装软件包,但在安装

npm install nodemailer

is ok? 可以吗

in both instances, the message returned was 在这两种情况下,返回的消息都是

WARN Invalid name: "try node mailer"
WARN email No description
WARN email No repository field
WARN email No README field
WARN email No license field

but only in the second instance the node_modules directory is populated with the package 但仅在第二个实例中,使用程序包填充node_modules目录

I'd suggest that you use some of the other version matching ranges and avoid the asterix one,, as per specs @page: https://docs.npmjs.com/files/package.json#dependencies 我建议您按照规范@page使用其他一些版本匹配范围,并避免使用星号: https ://docs.npmjs.com/files/package.json#dependencies

I did it fine with this one: 我对这一点做得很好:

{
  "name": "test",
  "version": "1.0.0",
  "description": "my test",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "nodemailer": "~2"
  },
  "author": "",
  "license": "ISC"
}

hope that helps you 希望对您有帮助

Rather than using a wildcard, you can try "" instead. 您可以尝试使用""代替使用通配符。 Otherwise this seems to be working: 否则,这似乎可行:

{
  "name": "testr",
  "version": "1.0.0",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "nodemailer": "^4.0.1"
  },
  "author": "",
  "license": "ISC"
}

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

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