Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable NODE_ENV detection during install #8827

Closed
1 task
aspirisen opened this issue Dec 2, 2024 · 10 comments · Fixed by #8839
Closed
1 task

Disable NODE_ENV detection during install #8827

aspirisen opened this issue Dec 2, 2024 · 10 comments · Fixed by #8839

Comments

@aspirisen
Copy link

aspirisen commented Dec 2, 2024

Contribution

Describe the user story

There is automatic detection of NODE_ENV and as a result some dependencies could be omitted during install https://pnpm.io/cli/install#--prod--p

Sometimes you have set NODE_ENV before install, i.e. NODE_ENV=production and then all dev dependencies will not be installed, but they are required for build. The things can be even more complicated when install command is running by some wrapper tool, and you do not have a way to bypass flags to pnpm

Also, there can be a problem on CI where NODE_ENV can be set globally for a job

Describe the solution you'd like

Option 1 - disable defaults for --prod and NODE_ENV detection, always install all dependencies unless explicit flag is set to install only specific set of dependencies

Option 2 - add a config property to .npmrc to skip NODE_ENV detection and install all dependencies

Describe the drawbacks of your solution

No response

Describe alternatives you've considered

No response

@zkochan
Copy link
Member

zkochan commented Dec 3, 2024

I would be OK with "Option 1" (installing all dependencies, when NODE_ENV is set to `production). I don't know what @pnpm/collaborators think.

The reason this works like this currently is that npm CLI does it like this. Yarn seems to install everything. We can do it in v10 if we decide it soon.

@aspirisen
Copy link
Author

Also, the args are a bit confusing --prod and --dev and their combinations. Maybe it is better to remove them.

Since the possible default behavior will be to install all dependencies pnpm can have --skip-prod-deps and --skip-dev-deps args with false values by default (without detecting NODE_ENV), just to leave the possibility to install only specific set of dependencies

@BlackHole1
Copy link
Member

Personally, I'm not particularly satisfied with either option. I checked the documentation for npm and yarn. They are consistent in handling NODE_ENV=production:

npm/Yarn will not install any package listed in devDependencies if the NODE_ENV environment variable is set to production

Ref:

The handling method of npm and yarn is: If you want to install all dependencies after setting NODE_ENV=production, you can add a flag: --prod=false or --production=false

My main concerns are:

  1. This could cause destructive changes (potentially affecting many projects using pnpm).
  2. This is inconsistent with the behavior of other package managers, making it difficult for some projects to migrate from npm/yarn to pnpm.
  3. Although there is currently no package manager RFC in the open-source community, I believe we should align more closely with npm/yarn to avoid further fragmentation.

@aspirisen
Copy link
Author

aspirisen commented Dec 3, 2024

I just tried to run NODE_ENV=production yarn install and the dev deps have been installed, strange. Yarn version 1.22.22. Maybe I am missing something?

I am currently migrating from yarn to pnpm, and that was the reason for creating this issue, I do not remember that yarn didn't install dev dependencies on CI or docker when NODE_ENV is production.

UPD: Looks like dev deps in package json has been install, but probably by possible mistake in some prod deps where i.e. webpack was not in dev deps and by hoisting I were able to see webpack in node_modules and didn't notice NODE_ENV=production behavior during install

So yeah, looks like yarn doesn't install dev deps under NODE_ENV=production condition

@zkochan
Copy link
Member

zkochan commented Dec 3, 2024

I checked with the latest Yarn and it installed dev deps.

@aspirisen
Copy link
Author

Yes, looks like latest Yarn version installs dev deps under NODE_ENV=production

@BlackHole1
Copy link
Member

If the behavior of yarn is to install everything, then I prefer option 1.

@btea
Copy link
Member

btea commented Dec 3, 2024

I think option 1 makes more sense.

@KSXGitHub
Copy link
Contributor

Normally, I would prefer pnpm to not behave differently from Yarn and NPM, but Yarn and NPM are behaving differently themselves.

In this case, installing everything including dev dependencies rarely break anyone's workflow (unless they don't have enough disk space), so I prefer option 1.

@aspirisen
Copy link
Author

What about the arguments, maybe it is only me, but the fact that pnpm install --prod=false command installs all dependencies including production just blows my mind.

Also, their combination is not clean from the first glance, like pnpm install --prod=false --dev=true will install only dev deps, pnpm install --prod=true --dev=true will install only prod deps and pnpm install --prod=false --dev=false will install all deps

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

Successfully merging a pull request may close this issue.

5 participants