0

I cant find my mistake after updating the node engine to 14.x and using ESM instead of CommonJS: exampleroute.js

import express from "express";
const router = express.Router();
router.get("/exampleroute", async (req, res) => {
  console.log('......')
})
export default router;

server.js

import http from "http";
import express from "express";
import exampleroute from "./routes/exampleroute";
const server = express();
server.use("/exampleroute", exampleroute);
const httpServer = http.createServer(server);
const httpPort = 8080
httpServer.listen(httpPort, () => console.log(`server is running @ port: ${httpPort}`));

Leads to: Error [ERR_MODULE_NOT_FOUND]: Cannot find module

What am I doing wrong?

1 Answers1

0

Try using:

import exampleroute from "./routes/exampleroute.js";

ref. Can't import "mysql2/promise" into ES module (MJS) on Node.js 13 / 14

rkJun
  • 311
  • 2
  • 7