节点:internal/process/esm_loader:94internalBinding('errors').triggerUncaughtException(^
错误[ERR_MODULE_NOT_FOUND]:找不到模块"D:\work\MERN\memoryApp\server\routes\post"从D:\work\MERN\memoryApp\server\index.js导入你的意思是进口/routes/post.js?在新的NodeError(节点:内部/错误:371:5)在finalizeResolution(节点:internal/modules/esm/resolve:418:11)在moduleReve(节点:internal/modules/esm/resole:981:10)在defaultResolve(节点:internal/modulesesm/resol:1078:11)在ESMLoader.resolve(节点:internal/modules/esm/loader:530:30)在ESMLoader.getModuleJob(节点:internal/modules/esm/loader:251:18)ModuleWrap。(节点:internal/modules/esm/module_job:79:40)在链接(节点:internal/modules/esm/module_job:78:36){代码:'ERR_MODULE_NOT_FOUND'}
import express from "express"
import bodyParser from "body-parser"
import mongoose from "mongoose"
import cors from "cors"
import postRoutes from "./routes/post"
const app=express();
app.use("/post",postRoutes);
app.use(bodyParser.json({limit:'22mb',extended:true}));
app.use(bodyParser.urlencoded({limit:'22mb',extended:true}));
app.use(cors());
const CONNECTION_URL="mongodb+srv://memoryApp:memoryApp@cluster0.i3xr8.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"
const PORT=process.env.PORT || 5000
mongoose.connect(CONNECTION_URL,{useNewUrlParser:true,useUnifiedTopology:true})
.then(()=>app.listen(PORT,()=>console.log(`Server is running on: ${PORT}`)))
.catch((err)=>console.log(err.message))
在我的情况下,我只是使用"导入postRouter/"路线/岗位";而不是"/routes/post.js";。这很有趣,但很管用,有人能告诉我为什么吗?
此import postRoutes from "./routes/post"
应改为import postRoutes from "./routes/post.js"
。