(node:9511) ExperimentalWarning: The ESM module loader is experimental

Viewed 37189

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

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 : https://nodejs.medium.com/announcing-a-new-experimental-modules-1be8d2d6c2ff

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.

Related