non recursive --dev install #3007

Closed
dsn opened this Issue Dec 18, 2012 · 10 comments

Comments

Projects
None yet
5 participants

dsn commented Dec 18, 2012

I have a module that includes devDependencies in the package.json however when I install with the '--dev' flag this installs the dev versions of all of my dependencies, when all I want to do is get the dev version of my module so I can safely and cleanly separate unit tests and development docs from the production release.

If there is already a way to do this I apologize and if you can point me to a doc on how I would appreciate it.

Contributor

luk- commented Apr 23, 2013

This is intended behavior. If you only want to install devDependencies for your root module, just run npm install, which will install the main devDependencies as long as you do not have the --production flag set.

luk- closed this Apr 23, 2013

Contributor

zeke commented Feb 26, 2014

I'm having the same problem. Why is recursive installation of dev deps the intended behavior?

$ cat package.json | jq .devDependencies
{
  "mocha": "^1.17.1"
}

$ export npm_config_dev=1

$ npm install
# ^ running for over an hour now...

$ du -hs node_modules
1.1G  node_modules
Member

domenic commented Feb 26, 2014

Because that's what the flag "dev" means, literally. If you don't want that behavior, I'd suggest not turning on the dev flag.

Contributor

zeke commented Feb 26, 2014

Some background: Heroku's node buildpack runs npm install --production, but many users want to run build steps during deployment that depend on things in devDependencies. Typically these are deps like bower or grunt plugins. Because they're accustomed to running npm install locally, users are confused when their build task fails because of missing dependencies.

A few alternatives have been considered:

  1. Make the buildpack do npm install without the production flag. This means slower first builds and bigger app tarballs, but a step closer to dev-prod parity.
  2. Add some conditional to the buildpack's compile script: If $INSTALL_DEV_DEPENDENCIES is present, run npm install, else npm install --production.

I don't really like either of these options, though. The first means slower and heavier builds, the second means vendor-specific configuration. I found npm's dev and was hoping it was the answer, but apparently not. Is there another way to configure npm's install behavior with environment variables?

dsn commented Feb 26, 2014

Wouldn't devDependencies describe the dependencies required to do development on the module not specify the version of dependencies you want to install?

Versions are controlled in different ways so I am confused as to why --dev is an override what versions of the dependencies you have.

If devDependancies are not as described dependencies for development why would I not list these just as dependencies and require everyone install them? Not everyone needs to have 'lint' tools installed to use my module but as there is task to check code syntax and style when building this would be a 'development only dependency'

This was my understanding of how this was supposed to work and what the switch did

Member

domenic commented Feb 26, 2014

The opposite of production=true is production=false. You could try setting that with environment variables, although I don't recall offhand whether environment variables or command-line flags take precedence, if heroku is forcing production=true via command-line flags.

Member

domenic commented Feb 26, 2014

@dsn I am not sure where you got the idea that dev overrides versions; that is not the case and nothing in this thread indicates that.

Contributor

zeke commented Feb 26, 2014

I don't recall offhand whether environment variables or command-line flags take precedence

Yeah, I meant to ask about this too. Is the precedence documented somewhere?

It seems that just running npm install might not actually do the trick (of installing devDependencies) as the NODE_ENV or npm_config_production env vars could step on its toes. Not sure though..

Contributor

zeke commented Feb 26, 2014

More context on the above comment, from @jamischarles: heroku/heroku-buildpack-nodejs#90 (comment)

Contributor

kapouer commented May 2, 2014

for people seeking a quick workaround:
npm_config_production=0 npm install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment