I am trying to use ES6 on server side. I a have separated endpoint from server file:
archive.js:
import { Router } from "express";
const router = Router();
router.get("/", async (req, res) => { "some code"});
export default router;
when i want to import it to my server file like this:
import archive from "./endpoints/archive.js";
app.use("/archive", archive);
it gives me an error:
(node:9565) ExperimentalWarning: The ESM module loader is experimental. internal/modules/run_main.js:54 internalBinding('errors').triggerUncaughtException()
any idea guys? i dont want to go back to require/module.exports
.js
file is assumed to be a CommonJS file, NOT an ESM module unless you have appropriately tagged it in a package.json file. It is much easier to get ESM modules to work by making them.mjs
files, not.js
files because the loader assumes any.mjs
file is an ESM module. Which file does this warning/error occur in? – Srinagar