I build a expressJs app by ES6 and I got the below error:
(node:4132) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/run_main.js:54
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'E:\wamp64\www\myDemos\nodeJs\expressJsExample\config\app' imported from E:\wamp64\www\myDemos\nodeJs\expressJsExample\server.mjs
←[90m at finalizeResolution (internal/modules/esm/resolve.js:255:11)←[39m
←[90m at moduleResolve (internal/modules/esm/resolve.js:603:10)←[39m
←[90m at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:644:13)←[39m
←[90m at Loader.resolve (internal/modules/esm/loader.js:94:40)←[39m
←[90m at Loader.getModuleJob (internal/modules/esm/loader.js:240:28)←[39m
←[90m at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:42:40)←[39m
←[90m at link (internal/modules/esm/module_job.js:41:36)←[39m {
code: ←[32m'ERR_MODULE_NOT_FOUND'←[39m
}
[nodemon] app crashed - waiting for file changes before starting...
If I use import app from './config/app.js';
then working but if I use import app from './config/app';
then return the above error.
The below is my code:
package.json
{
"name": "ExpressJsExample",
"version": "1.0.0",
"description": "Express Js Example",
"main": "server.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon server.js"
},
"author": "Mukesh Singh Thakur",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"chalk": "^4.0.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"http": "0.0.1-security",
"http-errors": "^1.7.3",
"jsonwebtoken": "^8.5.1",
"nodemon": "^2.0.2",
"pg": "^8.0.0",
"request": "^2.88.2",
"sequelize": "^5.21.6"
},
"devDependencies": {
"sequelize-cli": "^5.5.1"
}
}
server.js
import http from 'http';
import app from './config/app';
const server = http.Server(app);
server.listen(3000, () => {
return true;
});
app.js
import express from 'express';
const app = express();
export default app;
The example app is available in https://github.com/msthakur08/express-js-example
URL. The example files import with '.js' existence but I want to import file without '.js' existence.