[英]Node+ExpressRouter -> CommonJS to ESM --> Import routes --> Error [ERR_MODULE_NOT_FOUND]: Cannot find module
I cant find my mistake after updating the node engine to 14.x and using ESM instead of CommonJS: exampleroute.js将节点引擎更新到 14.x 并使用 ESM 而不是 CommonJS 后,我找不到我的错误:exampleroute.js
import express from "express";
const router = express.Router();
router.get("/exampleroute", async (req, res) => {
console.log('......')
})
export default router;
server.js服务器.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导致:错误 [ERR_MODULE_NOT_FOUND]:找不到模块
What am I doing wrong?我究竟做错了什么?
Try using:尝试使用:
import exampleroute from "./routes/exampleroute.js";
ref.参考。 Can't import "mysql2/promise" into ES module (MJS) on Node.js 13 / 14
无法在 Node.js 13 / 14 上将“mysql2/promise”导入 ES 模块(MJS)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.