Solution To Fix The Error: “ERR_REQUIRE_ESM” in NodeJS Script While I learned the NodeJS and triggered the error code “ERR_REQUIRE_ESM” I am going to use the mime package to get the mime type of the requested resource file to set the content type in the header of the response. I searched for a query regarding the […]
While I learned the NodeJS and triggered the error code "ERR_REQUIRE_ESM" I am going to use the mime package to get the mime type of the requested resource file to set the content type in the header of the response.
I searched for a query regarding the error message on the search engine many times and tried everything that the search engine and Stackoverflow answers suggested but I solved it by downgrading the version.
So, the solution for this error is just to downgrade the version. Because most of the packages transfer their code into the typescript and pure NodeJS can not understand it we had to downgrade the package version where they only used pure javascript code and no typescript file.
And one more thing that I found is that the mime package is better than the "file-type". While I used file-type to get the CSS and javascript files it returned undefined but mime works like a charm.
Thanks.