ERR_MODULE_NOT_FOUND

Issue

I’m getting this error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'C:\Users\nghia\OneDrive\Máy tính\nodebasic\src\configs\viewEngine' imported from C:\Users\nghia\OneDrive\Máy tính\nodebasic\src\server.js
    at new NodeError (internal/errors.js:322:7)
    at finalizeResolution (internal/modules/esm/resolve.js:318:11)
    at moduleResolve (internal/modules/esm/resolve.js:776:10)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:887:11)
    at Loader.resolve (internal/modules/esm/loader.js:89:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:76:40)
    at link (internal/modules/esm/module_job.js:75:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

my package.json file:
package.json

and this is sever.js:
server.js

Solution

import, by default, looks from files with the .mjs extension. In order to import a .js file, you need to explicitly state its extension:

import configViewEngine from './configs/viewEngine.js'

Answered By – Mureinik

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published