为什么 npm install 没有更新我的 package.json?

Why isn't my package.json updated by npm install?

我刚开始使用 npm,据我所知,npm install 命令应该会自动更新 package.json 文件,但不幸的是,我不会。

我在 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 抱怨它不在带有 extraneous 标志的 package.json 文件中:

$ 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 文件中?那不应该自动去吗?我在这里做错了什么?欢迎所有提示!

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