Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 5
    Holy cow...out of desperation I typed in "Error: Cannot find module" into google, and found this question. Your answer fixed my problem. I can't believe such a vague search term turned up the right answer. Kudos to you and to Google! Commented Dec 21, 2017 at 10:00
  • 3
    Very much this. I had managed to point the main entry for my submodule in a directory that was excluded from its repository so when I tried to include it via npm install it worked, but no exports were found when required in! Many thanks for this obvious but useful answer.
    – Dragos
    Commented Feb 26, 2019 at 11:13
  • 2
    Thanks for this. I had this situation whilst using Yarn workspaces, so was looking all over for path resolution algorithms and all sorts. :) I was thrown by the way the error message talks of 'locating' the module, and also that ESLint was giving similar error messages. And then I saw your answer and realised I was a dimwit. Thanks! Commented Sep 17, 2019 at 10:37
  • Where is the package.json file? Can someone provide more context? I've been using VS Code for a year and have successfully written all kinds of coding projects, but I'm new to NodeJS, and need a step by step on how to fix this very frustrating issue. Everything else I've tried right on this page does not work, or there just isn't enough context. Commented Oct 28, 2022 at 8:23