最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - dependencies not showing in package.json in Node.js - Stack Overflow

programmeradmin1浏览0评论

I am new to node.js. I know when I install a new module in node.js using npm install it gets installed but in package.json i cant find the package name in dependencies. I know i can type it out but it should appear when i install it using command prompt it should appear. Here's my package.json file. `

{
  "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://[email protected]:29418/CommunityPlatform/testing/mapfeedback-test"
  },
  "author": "",
  "license": "ISC",
  "keywords": [] }

Please advice and let me know if I am wrong at something.

I use npm install command to install all the packages but its not showing in the dependencies.

`

I am new to node.js. I know when I install a new module in node.js using npm install it gets installed but in package.json i cant find the package name in dependencies. I know i can type it out but it should appear when i install it using command prompt it should appear. Here's my package.json file. `

{
  "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://[email protected]:29418/CommunityPlatform/testing/mapfeedback-test"
  },
  "author": "",
  "license": "ISC",
  "keywords": [] }

Please advice and let me know if I am wrong at something.

I use npm install command to install all the packages but its not showing in the dependencies.

`

Share Improve this question asked Jul 4, 2016 at 8:51 JatinJatin 6703 gold badges8 silver badges29 bronze badges
Add a comment  | 

7 Answers 7

Reset to default 17

Quickest way to fix this would be to run:

npm install <dependencies listed here> --save

And that should add them to the package.json

Update:

Couple of extra commands for future viewers of the OP:

To add the package to your devDependencies instead of dependencies

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


There are also some handy shortcuts for both commands:

dependencies:

  • npm i <dependencies listed here> -S

dev-dependencies:

  • npm i <dependencies listed here> -D

The npm documentation is here.

And if you are a fan of shortcuts and npm configuration here is a useful link to find even more.

For npm packages to appear in package.json automatically you need to use this command:

 npm install packagename --save

Use following command

npm install <pkg-name> --save

--save instructs npm to include package inside dependencies of package.json

You need to install using --save or --save-dev switches.

Official documentation on this page: https://docs.npmjs.com/getting-started/using-a-package.json

i had that problem on linux and i figured out that i just use npm i <pkgs list here> to install my dependencies. then i used this command to install them:

npm i -S <pkgs list here>

the -S will save them as dependencies and puts the list of installed pkgs under dependencies: { ... } object in package.json file.

please note that without -S flag , npm will install them but not list them in package.json file

If You are on linux or a mac and you have not configured your permissions very well You may need to prefix sudo sudo npm install <dependencies listed here> --save

Use below line of code: npm install --save packagename

发布评论

评论列表(0)

  1. 暂无评论