在Node.js中的package.json中没有显示依赖项

Jat*_*tin 6 javascript json node.js

我是node.js的新手.我知道当我使用npm install在node.js中安装新模块时,它会被安装但是在package.json中我无法在依赖项中找到包名.我知道我可以输入它,但它应该出现当我使用命令提示符安装它应该出现.这是我的package.json文件.`

{
  "name": "mapfeedback-test",
  "version": "1.0.0",
  "description": "Map feedback Javascript Test library 1.0",
  "main": "client.js",
  "bin": {
    "mapfeedback-test": "server.js"
  },
  "directories": {
    "doc": "docs"
  },
  "dependencies": {},
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "repository": {
    "type": "git",
    "url": "ssh://jasharma@gerrit.it.here.com:29418/CommunityPlatform/testing/mapfeedback-test"
  },
  "author": "",
  "license": "ISC",
  "keywords": [] }
Run Code Online (Sandbox Code Playgroud)

如果我做错了,请建议并告诉我.

我使用npm install命令来安装所有软件包,但它没有显示在依赖项中.

`

ale*_*xi2 11

解决这个问题的最快方法是运行:

npm install <dependencies listed here> --save
Run Code Online (Sandbox Code Playgroud)

那应该将它们添加到package.json中

更新:

针对OP的未来观众的额外命令:

要将包添加到您的devDependencies而不是dependencies

npm install <dependencies listed here> --save-dev


这两个命令还有一些方便的快捷方式:

依赖关系:

  • npm i <dependencies listed here> -S

DEV-依赖关系:

  • npm i <dependencies listed here> -D

npm文档在这里.

如果你是快捷方式和npm配置的粉丝,这里是一个有用的链接,可以找到更多.


Sha*_*tri 5

要使npm包自动出现在package.json中,您需要使用以下命令:

 npm install packagename --save
Run Code Online (Sandbox Code Playgroud)