cli icon indicating copy to clipboard operation
cli copied to clipboard

`nuxi module add` always install module as dependcies, even it should be `devDependencies`

Open gxres042 opened this issue 1 year ago • 4 comments

For example, when I install @nuxt/eslint, for pnpm, I will install eslint and @nuxt/eslint as devDepencies:

pnpm add -D @nuxt/eslint eslint

But when I use nuxi module add eslint, it runs:

pnpm add @nuxt/eslint // didn't have eslint

gxres042 avatar Jul 30 '24 11:07 gxres042

Actually this is how we detect where to install the dependency: https://github.com/nuxt/cli/blob/bca75ab6490dfc444e3b6766ba5c47572622e2d3/src/commands/module/add.ts#L63

I think we can add an exception for @nuxt/eslint to force being a dev dependency anyway

Happy to open a PR for it?

atinux avatar Jul 31 '24 10:07 atinux

Maybe try it 🥰

gxres042 avatar Aug 01 '24 02:08 gxres042

@Atinux I found a question

When initializing a Nuxt 3 project, nuxt and vue are installed by default as dependencies instead of devDependencies. The detection above is done by checking if nuxt is a devDependency, i.e. if nuxt in the user's project is not a devDependency, then any dependencies added by the user's module add will not be installed as devDependencies.

I'm not quite sure if all the official Nuxt modules need to be installed as devDependencies, but what I do know so far is that the manual install of @nuxt/eslint requires it and eslint to be installed as devDependencies.

gxres042 avatar Aug 01 '24 04:08 gxres042

Actually, everything can be a devDependency in Nuxt 3 as we bundle everything for production (including the depdendencies used) :)

atinux avatar Aug 12 '24 10:08 atinux

in general I would think modules should match nuxt rather than forcing modules to development mode. installing a module in dev mode (but nuxt in prod mode) would lead to a build failure if installing dependencies with --production. all modules will be required in the same environment as nuxt (i.e the build environment).

if anything we could support a flag to allow the user to choose (--dev).

danielroe avatar Oct 22 '24 13:10 danielroe