npm没有按预期工作

时间:2016-03-14 20:40:54

标签: node.js npm npm-install

任何目录npm install运行package.json目前对我不起作用。我甚至尝试过一些众所周知的项目,但问题是一样的,所以我想我并没有弄乱我的package.json

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

我以前曾使用过相同的代码来使用git,而npm install只是在node_modules中生成了 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": ""
}

1 个答案:

答案 0 :(得分:3)

npm的这种行为已从版本2更改为3及更高版本:版本2及更早版本使用了子文件夹。从版本3开始,您将获得扁平的封装结构。所以你现在看到的是以前所有的瞬态依赖关系,它们都是4个依赖关系的子文件夹(node_modules)。

但是,最终行为应该完全相同。

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