[BUG] Cannot set property 'peer' of null
Problem
Is there an existing issue for this? - [X] I have searched the existing issues This issue exists in the latest npm version - [X] I am using the latest npm Current Behavior I can only hit this particular error in a certain directory with a certain package, but I can reproduce it over several npm versions and it's 100% of the time. There are more examples available in #3711 (the author refuses to reopen the bug even though it is not fixed and people are hitting it!). After having a working npm for years and not changing the config, I just ran into it on npm v8.1.4. Upgraded to v8.5.4 and the problem did not go away. Here's the log with the latest version (8.12.1): [code block] I redacted the user and package name as they are company internals. I use a company artifactory with npm registry. However, this has worked for me before and is working for thousands of our developers as we speak, so I think it's a local problem with my npm. Expected Behavior `npm i <package>` installs the package successfully Steps To Reproduce 1. In this environment... 2. With this config... 3. Run '...' 4. See error... Environment - npm: v8.12.1 - Node.js: v17.2.0 - OS Name: Windows 10 x64 - npm config: [code block]
Error Output
error in a certain directory with a certain package, but I can reproduce it over several npm versions and it's 100% of the time.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix Null Peer Property Error in npm Install
The error 'Cannot set property 'peer' of null' typically occurs when npm encounters a corrupted or improperly configured package or dependency in the specified directory. This can happen due to a misconfigured package-lock.json, a corrupted node_modules directory, or an issue with the npm cache that leads to npm trying to access a non-existent object.
Awaiting Verification
Be the first to verify this fix
- 1
Clear npm cache
Clear the npm cache to remove any corrupted files that may be causing the issue.
bashnpm cache clean --force - 2
Delete node_modules and package-lock.json
Remove the node_modules directory and package-lock.json file to reset the package state.
bashrm -rf node_modules package-lock.json - 3
Reinstall packages
Run npm install to reinstall all packages and regenerate the package-lock.json file.
bashnpm install - 4
Check for specific package issues
If the issue persists, check if the specific package causing the error has known issues or updates. You can do this by visiting the package's repository or issue tracker.
bashnpm view <package-name> issues - 5
Verify npm configuration
Ensure that your npm configuration is correct and does not contain any invalid settings that could lead to this error. You can reset your npm configuration to default if necessary.
bashnpm config ls -l
Validation
To confirm the fix worked, run 'npm install <package>' in the original directory where the error occurred. If the installation completes without errors, the issue has been resolved.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep