npm 没有按预期工作

npm doesn't work as expected

运行ning npm install from any directory having package.json 目前对我不起作用。我什至在一些知名项目上尝试过,但问题是一样的,所以我想这不是我搞砸了我的 package.json.

所以问题是,npm install 实际上在我的本地 node_modules 目录中安装了大约 241 个模块。虽然我在 package.json 中清楚地只列出了 3 个。 npm 行为突然一次又一次地安装,每次我 运行 它。

我以前使用相同的代码提交给 git 和 npm install 只是在我的 node_modules.[=23 中产生了 3 个包=]

$ npm -v
3.8.1

$ node -v
v5.8.0

里面的模块列表node_modules

$ ls node_modules/
ansi-regex        color-convert           extract-zip               gulp-concat        isstream                lodash.template          ordered-read-streams  request                supports-color
ansi-styles       combined-stream         extsprintf                gulp-util          jodid25519              lodash.templatesettings  os-homedir            resolve                throttleit
archy             commander               fancy-log                 gulplog            jsbn                    loud-rejection           parse-json            rimraf                 through2
array-differ      concat-map              fd-slicer                 har-validator      json-schema             lru-cache                path-exists           semver                 tildify
array-find-index  concat-stream           find-index                has-ansi           json-stringify-safe     map-obj                  path-is-absolute      sequencify             time-stamp
array-uniq        concat-with-sourcemaps  find-up                   has-gulplog        jsonpointer             meow                     path-type             sigmund                tough-cookie
asn1              core-util-is            findup-sync               hawk               jsprim                  mime-db                  pend                  signal-exit            trim-newlines
assert-plus       cryptiles               first-chunk-stream        hoek               liftoff                 mime-types               pify                  single-line-log        tunnel-agent
async             dashdash                flagged-respawn           home-path          load-json-file          minimatch                pinkie                sntp                   tweetnacl
aws-sign2         dateformat              forever-agent             hosted-git-info    lodash                  minimist                 pinkie-promise        source-map             typedarray
aws4              debug                   form-data                 http-signature     lodash._basecopy        mkdirp                   pretty-bytes          sparkles               unique-stream
balanced-match    decamelize              gaze                      indent-string      lodash._basetostring    ms                       pretty-hrtime         spdx-correct           user-home
beeper            deep-extend             generate-function         inflight           lodash._basevalues      multipipe                process-nextick-args  spdx-exceptions        util-deprecate
bl                defaults                generate-object-property  inherits           lodash._getnative       mv                       progress-stream       spdx-expression-parse  v8flags
boom              delayed-stream          get-stdin                 ini                lodash._isiterateecall  ncp                      pseudomap             spdx-license-ids       validate-npm-package-license
bower             deprecated              glob                      interpret          lodash._reescape        node-uuid                qs                    speedometer            verror
brace-expansion   duplexer2               glob-stream               is-arrayish        lodash._reevaluate      normalize-package-data   rc                    sshpk                  vinyl
builtin-modules   ecc-jsbn                glob-watcher              is-builtin-module  lodash._reinterpolate   nugget                   read-pkg              stream-consume         vinyl-fs
camelcase         electron-download       glob2base                 is-finite          lodash._root            number-is-nan            read-pkg-up           string_decoder         wrappy
camelcase-keys    electron-prebuilt       globule                   is-my-json-valid   lodash.escape           oauth-sign               readable-stream       stringstream           xtend
caseless          end-of-stream           glogg                     is-property        lodash.isarguments      object-assign            rechoir               strip-ansi             yallist
chalk             error-ex                graceful-fs               is-typedarray      lodash.isarray          object-keys              redent                strip-bom              yauzl
clone             escape-string-regexp    graceful-readlink         is-utf8            lodash.keys             once                     repeating             strip-indent
clone-stats       extend                  gulp                      isarray            lodash.restparam        orchestrator             replace-ext           strip-json-comments

package.json

{
  "name": "test",
  "version": "1.0.0",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "./node_modules/electron-prebuilt/dist/electron --harmony --enable-transparent-visuals ."
  },
  "author": "ishankhare07@gmail.com",
  "license": "MIT",
  "dependencies": {
    "bower": "^1.7.7",
    "electron-prebuilt": "^0.36.7",
    "gulp": "^3.9.1",
    "gulp-concat": "^2.6.0"
  },
  "devDependencies": {},
  "description": ""
}

npm 的这种行为已从版本 2 更改为版本 3 及更高版本:版本 2 和更早版本使用子文件夹。从版本 3 开始,您将获得扁平的包结构。因此,您现在看到的是之前作为 4 个依赖项的子文件夹 (node_modules) 提供的所有临时依赖项。

但是,最终的行为应该是完全一样的。

可以找到其背后的基本原理 here