Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

node.js - "npm install" installs all dependencies in node_modules directory, instead of having them nested

I need to know if the following behavior is normal.

When I npm install, each package from my package.json and the dependencies, don't get installed nested anymore, but each dependency is installed in the node_modules directory. That makes my node_modules directory blown and look like this:

Screenshot of node_modules directory

This happened since I updated npm and node.

Now I run:

npm -v 3.3.6
node -v 4.2.1
python 2.7
windows 7
wamp

My package.json file looks like this:

{
  "private": true,
  "devDependencies": {
    "gulp": "^3.8.8"
  },
  "dependencies": {
    "laravel-elixir": "^3.0.0",
    "bootstrap-sass": "^3.0.0"
  }
}

It's the standard laravel package.json file.

Is there a way to have nested directories again, because I don't like such a blown article with over 100 sub directories.

question from:https://stackoverflow.com/questions/33154836/npm-install-installs-all-dependencies-in-node-modules-directory-instead-of-ha

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Update: As Erik Pukinskis mentioned in the comments: As of npm 3.5, support for --legacy-bundling has been dropped.


Yes, there is a way to have nested directories again by changing npm's (version 3 as of this writing) default behaviour:

  1. Delete the currently present node_modules folder.

  2. Tell npm to install with legacy bundling for this one install:

    npm install --legacy-bundling

A "permanent" alternative:

  1. Set your npm config to always use legacy bundling...

    npm set legacy-bundling=true

  2. .. and run as usual:

    npm install

Note: fetching dependencies with legacy bundling will take a lot more time because many several different versions of the same dependencies will be installed.

Disclaimer: As a non-Windows user I have no need for flat dependencies and want to find self-declared dependencies with ease in favour of automatic deduping. Since installing npm dependencies without legacy bundling already takes an incredible amount of time I'm usually willing to spend those extra minutes install time. It gets back down to 5 directories from previously 700+ (...) in a Laravel Elixir setup with bootstrap (non-sass), font-awesome and jquery added.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...