简体   繁体   English

Node+ExpressRouter -> CommonJS 到 ESM --> 导入路由 --> 错误 [ERR_MODULE_NOT_FOUND]: 找不到模块

[英]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?我究竟做错了什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM