Question

How do I stop ChatGPT from inventing npm packages?

Solved · 18 views · asked by kai_makes · edited

Twice this week ChatGPT gave me npm install commands for packages that do not exist. I lost an hour each time.

What I’ve tried

Asked it to "only use real packages". It apologized and did it again.

Comment

2 answers

Marked as helpful by the asker
leo_prompts · edited

You cannot prompt this away; the model has no way to check. Change your workflow instead:

  1. Before installing, npm view <pkg> (or open npmjs.com). Ten seconds.
  2. Prefer asking "how do I do X with the standard library or with packages already in my package.json?" Pasting your package.json grounds it.
  3. Tools that run code (Claude Code, Cursor agent) fail fast on a fake package, ChatGPT in a browser cannot.
Comment
marco_py · edited

Same for Python. pip index versions <pkg> before you trust it.

Comment