Search code examples
node.jsexpressnodemon

Why I'm getting Error [ERR_MODULE_NOT_FOUND]: Cannot find module when running the server


I'm doing a startup server. Basically It has initial setup with express and nodemon dependencies. Unfortunately, I'm getting ERR_MODULE_NOT_FOUND when running yarn dev or npm run dev Here is the code and file structure I have. enter image description here


Solution

  • You need to add .js extension index.js:

    import { SampleExport } from "../path/file.js"
    

    In my opinion, it is better to use .env files together with some npm package or even a json file.