为什么我的package.json不是由npm install更新的?

时间:2017-10-18 15:56:17

标签: javascript node.js npm npm-install package.json

我刚刚开始使用npm,据我所知,npm install命令应该会自动更新package.json文件,但遗憾的是,我没有。{/ p>

我在OSX上并在一个名为npmtest的新目录中执行了以下操作:

$ ls  # let's first confirm the folder is empty
$
$ npm init --y
Wrote to /Users/kramer65/Downloads/npmtest/package.json:

{
  "name": "npmtest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

然后我安装了下划线:

$ npm install underscore
npmtest@1.0.0 /Users/kramer65/Downloads/npmtest
└── underscore@1.8.3

npm WARN npmtest@1.0.0 No description
npm WARN npmtest@1.0.0 No repository field.

似乎安装得很好:

$ ls -l
total 8
drwxr-xr-x  3 kramer65  staff  102 Oct 18 17:47 node_modules
-rw-r--r--  1 kramer65  staff  221 Oct 18 17:47 package.json

遗憾的是npm list抱怨它不在package.json文件中extraneous标志:

$ npm list
npmtest@1.0.0 /Users/kramer65/Downloads/npmtest
└── underscore@1.8.3 extraneous

npm ERR! extraneous: underscore@1.8.3 /Users/kramer65/Downloads/npmtest/node_modules/underscore

我可以确认:

$ cat package.json
{
  "name": "npmtest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

问题是;为什么不在package.json文件中输入?不应该自动进行吗?我在这做错了什么?欢迎所有提示!

1 个答案:

答案 0 :(得分:2)

npm install没有更新package.json文件,npm install *module name* --save更新json包。希望有所帮助。