npm不能按预期工作

时间:2022-05-02 21:46:08

running npm install from any directory having package.json is not working for me at the moment. I've even tried it with some well known projects but the problem is same, so I guess it's not me messing up with my package.json.

从包含package.json的任何目录运行npm install目前对我不起作用。我甚至尝试了一些众所周知的项目,但问题是一样的,所以我想这不是我搞砸了我的package.json。

So the problem is, npm install actually install about 241 modules in my local node_modules directory. While i have clearly listed just 3 in package.json. npm behaves abruptly installing the again and again, everytime I run it.

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

I previously worked with same code committed to git and npm install just resulted in 3 packages in my node_modules.

我以前使用相同的代码提交到git和npm install只是在我的node_modules中产生了3个包。

$ npm -v
3.8.1

$ node -v
v5.8.0

list of modules inside node_modules

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

的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 个解决方案

#1


3  

This behaviour of npm has changed from version 2 to 3 and later: version 2 and older used subfolders. Since version 3 you get a flat package structure. So what you now see is all the transient dependencies that before were available as subfolders (node_modules) of your 4 dependencies.

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

However, the final behaviour should be exactly the same.

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

The rationale behind this can be found here.

这背后的基本原理可以在这里找到。

#1


3  

This behaviour of npm has changed from version 2 to 3 and later: version 2 and older used subfolders. Since version 3 you get a flat package structure. So what you now see is all the transient dependencies that before were available as subfolders (node_modules) of your 4 dependencies.

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

However, the final behaviour should be exactly the same.

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

The rationale behind this can be found here.

这背后的基本原理可以在这里找到。