[BUG] running npm install without a package.json shouldn't create a package-lock.json if it errors
broksonic21 opened this issue · comments
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
in a folder without a package.json, npm install
errors out but still creates a package-lock.json.
When you are in a non-node project but run npm i
by mistake you end up with an extra file you then need to revert for git. would be better if it didn't create one at all.
Expected Behavior
I feel like it shouldn't create a package-lock.json in this setup
Steps To Reproduce
-
mkdir -p testFolder
-
cd testFolder
-
npm install
-
Get this error:
```
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/REDACTED/tmp/testFolder/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/REDACTED/tmp/testFolder/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoentnpm ERR! A complete log of this run can be found in: /Users/REDACTED/.npm/_logs/2024-05-06T13_30_07_880Z-debug-0.log ```
-
with a file that looks like this:
{
"name": "testFolder",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}
Environment
- npm: 10.1.0
- Node.js: 20.9.0
- OS Name: Mac
Closing: this looks to be similar if not a duplicate of an existing issue, #6986. If you believe your instance is unique, please provide further clarifying details.
hadn't seen that old ticket - that works, thanks!