I'm trying to import my "fake" database which i create like database.js but when i try to import that into the index.ejs its says cannot find module.
import database from "./database"
I just had an basic folder called EXPRESS.JS and inside that i had database.js "here is the error message `Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/mirza/Desktop/EXPRESS.JS/database' imported from /home/mirza/Desktop/EXPRESS.JS/index.js
Did you mean to import ../database.js?`"
CodePudding user response:
Remove ".js" from folder name.
It'll works.
Otherwise, import like below.
import database from "../database.js"
CodePudding user response:
Some setups require you to include the file ending in import statements, so /database.js would be necessary. Many other setups automatically work without the file ending.
If the .JS ending in the folder name is not the problem as noted by another contributor, adding .js to the file name should resolve it.