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

Feature request: Add config option to prevent accidental installation of packages in directories without package.json #7724

Closed
sryze opened this issue Aug 15, 2024 · 2 comments

Comments

@sryze
Copy link

sryze commented Aug 15, 2024

For example, I have a project with a nested structure (monorepo) where frontend code is located a few levels deep in the directory hierarchy:

project/
- module1
--- ...
- module2
--- src
--- frontend-src/
------ package.json
------ package-lock.json
------ node_modules

I often accidentally run npm install to add a new frontend dependency while being in the wrong directory, which results in automatic creation of node_modules, package.json, package-lock.json in the wrong place. I don't how many people besides me run into this problem, maybe everyone else is much more disciplined about checking their CWD.

If indeed it's a common problem, I would like to propose a config flag that could be added to ~/.npmrc to prevent situations like this, i.e. only allow installing non-global packages while inside a directory with an existing package.json file.

install-only-with-package-json = true
@kchindam-infy
Copy link

Hi @sryze
Thank you for the suggestion, According to GitHub guidelines, new feature and suggestions are discussed in the npm feedback forum. Recommended to open a discussion in the npm feedback forum. You can visit here https://github.com/npm/feedback/discussions

@sryze
Copy link
Author

sryze commented Aug 25, 2024

@kchindam-infy OK, thanks. BTW the correct discussion link seems to be this: https://github.com/orgs/community/discussions/categories/npm?discussions_q=category%3Anpm

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

No branches or pull requests

3 participants