Skip to content
This repository has been archived by the owner. It is now read-only.

npm install --no-optional installs optional dependencies anyway #17633

Closed
akdor1154 opened this issue Jul 6, 2017 · 24 comments

Comments

Projects
None yet
@akdor1154
Copy link

commented Jul 6, 2017

I'm opening this issue because:

  • npm is crashing.
  • npm is producing an incorrect install.
  • npm is doing something I don't understand.
  • Other (see below for feature requests):

What's going wrong?

If I have an optional dependency specified in my project's package.json, npm install --no-optional will install it anyway.

How can the CLI team reproduce the problem?

npm init  # enter, enter, enter...
npm install --save-optional typescript
npm remove --no-save typescript
npm install --no-optional
# typescript gets installed again.
# typescript should not be installed at this point.

npm 5.10.0, OS X.

@zkat zkat added npm5 bug labels Jul 6, 2017

@zkat

This comment has been minimized.

Copy link
Member

commented Jul 6, 2017

yup this definitely seems to be happening 🤔

@stefcameron

This comment has been minimized.

Copy link

commented Jul 26, 2017

I'm seeing this today with npm 5.3.0. npm install --no-optional works IIF a package-lock.json does not exist. If the package-lock.json file exists, then the flag is ignored and all dependencies get installed.

@aequasi

This comment has been minimized.

Copy link

commented Sep 4, 2017

Seeing this as well, on 5.4.0 today

@ba55ie ba55ie referenced this issue Oct 18, 2017

Closed

npm install fails in windows using fsevents #17671

2 of 4 tasks complete
@smartmouse

This comment has been minimized.

Copy link

commented Oct 26, 2017

This is the behaviour I am seeing: npm i --no-option generates the package-lock.json file and it still have optional:true in it, I wonder if this is a bug with npm.
I would expect that optional:false.
My version of npm is 5.3.0

@laudeam

This comment has been minimized.

Copy link

commented Dec 5, 2017

Experiencing the same issue with npm 5.5.1

@flobacher

This comment has been minimized.

Copy link

commented Dec 13, 2017

issue still exists in npm 5.6.0

@buvinghausen

This comment has been minimized.

Copy link

commented Dec 29, 2017

Add a restore script to your package.json

"restore": "npm i --no-optional --no-package-lock",
"restore:prod": "npm run restore -- --only=production",

npm run restore

@laudeam

This comment has been minimized.

Copy link

commented Jan 22, 2018

Hi, is there a workaround available for this issue ?

Currently I have to use --production --no-shrinkwrap. This skips all optional dependencies installations but doesn't take package-lock.json into account :-/

Thanks

rogersp added a commit to rogersp/claudia that referenced this issue Feb 14, 2018

@cdierkens

This comment has been minimized.

Copy link

commented Mar 6, 2018

Any updates on this ticket?

@kochie

This comment has been minimized.

Copy link

commented Mar 6, 2018

I was playing around with a fix for this the other day, I'll have some time on the weekend to see if it works and I'll push a PR up.

@zkat

This comment has been minimized.

Copy link
Member

commented Mar 7, 2018

We're looking into it, FYI. This rabbit hole goes a bit deep into the installer, but it'll hopefully be fixed soon. Cheers. :)

@jdmarshall

This comment has been minimized.

Copy link

commented Mar 7, 2018

This happens at least as far back as npm 3.10.8.

We had been using this flag for a little while and I'm trying to work out what changed when it stopped functioning. I'll try to keep you posted.

Update: We had a shrinkwrap file sneak into an internal dependency.

@tcort

This comment has been minimized.

Copy link
Contributor

commented Mar 12, 2018

This is still an issue with npm 5.7.1 on node 8.10.0.

Steps to reproduce...

Create a package.json file with optionalDependencies...

{
  "name": "demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "optionalDependencies": {
    "lodash": "^4.17.5"
  }
}

Remove any existing install node_modules in order to "prove" that the next step is installing the optional stuff...

rm -rf node_modules

Do an install with --no-optional...

 npm install --no-optional

See that it installed the optional dependency...

ls node_modules

NOTE: there may be a bigger issue here with npm install flag handling. Using an unknown flag (e.g. npm install --i-like-golf) does not result in an error.

@andrew-polyansky

This comment has been minimized.

Copy link

commented Mar 28, 2018

This is still an issue with npm 5.8.0 on node 8.10.0.

@dannypaz

This comment has been minimized.

Copy link

commented Apr 26, 2018

This is STILL an issue w/ npm 5.6.0 and node 8.11.1

@grconrad

This comment has been minimized.

Copy link

commented Apr 27, 2018

Seems like it has been fixed in npm 6 and node 8.11.1

@zkat

This comment has been minimized.

Copy link
Member

commented Apr 27, 2018

Sounds like this has been fixed in npm6, so I'm closing this. Please upgrade to npm@6 if you see this issue.

@zkat zkat closed this Apr 27, 2018

@webpepper

This comment has been minimized.

Copy link

commented May 1, 2018

I on the other hand can't do anything now to prevent optional modules from being installed after upgrading to node 10.0.0 and npm 6.0.0 on macOS 10.13.4. Neither command line flags nor .npmrc file work.

> fsevents@1.2.3 install /Users/lobster/test/node_modules/fsevents
> node install

node-pre-gyp ERR! Completion callback never invoked!
node-pre-gyp ERR! System Darwin 17.5.0
node-pre-gyp ERR! command "/usr/local/bin/node" "/Users/lobster/test/node_modules/fsevents/node_modules/node-pre-gyp/bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/lobster/test/node_modules/fsevents
node-pre-gyp ERR! node -v v10.0.0
node-pre-gyp ERR! node-pre-gyp -v v0.9.1
node-pre-gyp ERR! This is a bug in `node-pre-gyp`.
node-pre-gyp ERR! Try to update node-pre-gyp and file an issue if it does not help:
node-pre-gyp ERR!     <https://github.com/mapbox/node-pre-gyp/issues>

--- other irrelevant output here ---

> purifycss-webpack@0.7.0 postinstall /Users/lobster/test/node_modules/purifycss-webpack
> node lib/post_install.js

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.3 (node_modules/fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.3 install: `node install`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 6

Rolling back to npm 5.8.0 fixes the optional dependency issue but shows this (which is unrelated, of course)

npm WARN npm npm does not support Node.js v10.0.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
npm WARN npm You can find the latest version at https://nodejs.org/

So it seems to be an npm 6 issue.

@sconix

This comment has been minimized.

Copy link

commented May 1, 2018

I am also facing the same issue that optional packages gets always installed after upgrading to npm 6. With npm 5.8.0 I was able to leave out optional packages by running: npm install --no-optional, but now with npm 6 the optional packages still get installed. I have tried everything, but for now I had to downgrade to 5.8.0 to get working install.

My setup is latest node 8.x + npm 6 running in latest stable Debian.

@webpepper

This comment has been minimized.

Copy link

commented May 3, 2018

Same problem on Windows 10. It's impossible to skip optional packages. Perhaps this issue should be reopened.

@sconix

This comment has been minimized.

Copy link

commented May 14, 2018

Now the problem is also in the 5.10.0 version. So could this be re-opened or some info provided how one should be able to make an install without optional packages. The last working version is 5.8.0 that actually leaves out optional packages when doing a clean install with: npm install --no-optional

@sconix

This comment has been minimized.

Copy link

commented May 29, 2018

@zkat could this be re-opened, even with npm 6.1 there is still no way to make an install without optional packages. This is blocking us from moving to npm 6 since in our project there are optional packages in the dependencies that will break the build for certain environments.

@antennaio

This comment has been minimized.

Copy link

commented Jul 10, 2018

The optional dependencies look like a great feature. Unfortunately npm ci --production --no-optional skips dev dependencies but installs optional dependencies... npm ci --no-optional installs dependencies, dev dependencies and optional dependencies.

My last hope npm ci --only=production also installs optional dependencies. :-)

I'm on npm 6.1.0 and have a package-lock.json file.

@zkat

This comment has been minimized.

@npm npm locked as resolved and limited conversation to collaborators Jul 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.