Skip to content

fix(arborist): Add better error message when lockfile is malformed #8268

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

Open
wants to merge 1 commit into
base: latest
Choose a base branch
from

Conversation

owlstronaut
Copy link
Contributor

@owlstronaut owlstronaut commented May 1, 2025

Overrides #6997 with a more standard way of expressing errors in the cli and has a test for it.

@owlstronaut owlstronaut marked this pull request as ready for review May 1, 2025 18:22
@owlstronaut owlstronaut requested a review from a team as a code owner May 1, 2025 18:22
@@ -200,6 +200,13 @@ module.exports = cls => class VirtualLoader extends cls {
const targetPath = resolve(this.path, meta.resolved)
const targetLoc = relpath(this.path, targetPath)
const target = nodes.get(targetLoc)

if (!target) {
const err = new Error(`Missing target in lock file: "${targetLoc}" is referenced by "${location}" but does not exist.\nThis is likely due to a damaged lock file. Remove the entry for "${location}" from your lock file and run npm install again.`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically we don't suggest folks editing their lockfile manually. Is there a better programmatic way to fix this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wraithgar fair point! I updated it. See what you think 😄

const err = new Error(
`Missing target in lock file: "${targetLoc}" is referenced by "${location}" but does not exist.
To fix:
1. rm -rf node_modules
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this overkill? Having node_modules will make this go much faster and keep churn down on the lockfile.

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

Successfully merging this pull request may close these issues.

2 participants