Open
Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
Running npm install
from a directory without a package.json creates a empty package.json
file.
Additionally, running npm --prefix some-directory install
will also create the directory.
Expected Behavior
100% of the time I have done this, it has been on accident and I then have to go and delete the directory and/or the package.json file it creates.
I think it would be better to add an error message output indicating that there is no package.json
present in the directory or the directory doesn't exist, and then suggesting I run npm init
instead.
Steps To Reproduce
- Create a new temporary directory wherever
mkdir temp
- Enter the directory
cd temp
npm --prefix temp2 install
Environment
- npm: 10.8.3
- Node.js: 22.9.0
- OS Name: MacOS Sonoma 14.6.1
- System Model Name: Apple M3 Pro