(Node:9511) Experimentalwarning: the Esm Module Loader Is Experimental
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()...
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
3 Answers
you can use Node v14.12.0; where this probleme is solved, and read this doc
I realize after a few tries that "--experimental-modules" flag on the "nodemon" causes issues to realize the imports in the whole app so I did update that flag to use the new flag for explicit filenames"--es-module-specifier-resolution=node" and now works perfect here is an article about this new flag :
So for explane you can do a script like this:
nodemon --es-module-specifier-resolution=node
Also keep in mind the nodejs version you use a version under 12.XX, 14.XX or the last stable version.
Upgrade Node.js to the latest version on Mac OS
I hoper this helps more developers :)
This was a new directory which i have pulled from github repo. I have tried many things/solutions but it turned out i have to clone to a new directory/environment. Couldnt find the problem or a proper fix but in the new directory/environment i dont have that problem.