npm WARN The package is included as both a dev and production dependency

My use-case is exactly what @Jim pointed out in the comment of the accepted answer, In development I wanted to use my local module files as I was working on it the same time I worked on my other projects using it. In production I would use the module from VCS, and I don't want to manually change the package.json file every time.

This is how I set up my package.json:

"dependencies": {
  "module-name": "git+ssh://[email protected]/XXX/XXX.git#master"
},
"devDependencies": {
  "module-name-dev": "file:../XXX"
}

With this setup, npm doesn't give me any errors, because the modules name are different, now what left to do is to require the dev package in development instead the main one.

I found the module-alias package, it allows you to use alias names for paths you want to require.

In your app.js file at the very beginning you need to add this code:

if (process.env.NODE_ENV === 'development') {
  const moduleAlias = require('module-alias');

  moduleAlias.addAlias('module-name', 'module-name-dev');
}

From now on, every time you require the module-name module, you will actually get the module-name-dev in development.

In production you shouldn't install the devDependencies, and the alias will not work, so no extra steps needed to change between the 2.

Working with webpack

If you are using webpack, you do not need the module-alias, you can add alias to the webpack config using webpack-chain like this:

chainWebpack: (config) => {
    if (process.env.NODE_ENV === 'development') {
      config.resolve.alias
      .set('module-name', 'module-name-dev');
    }
  },

You have the package referred to in both sections of your dependencies; you should totally not do this because it means that your production install will have a different version to your development install.

If you do npm install you will get all dependencies & devDependencies installed; however if you do npm install --production you only get dependencies installed.

You should remove things you don't need for your app to run from dependencies and place them in devDependencies. Things in dependencies should be seen as requirements to run the application (after any code transformation has occurred).

There is zero case where a dependency should be in both.