我无法使用heroku后构建脚本将MERN堆栈应用程序部署到heroku。我不断收到相同的错误,我将在下面列出。
Creating an optimized production build...
Failed to compile.
./src/App.js
Cannot find file './components/dashboard/SideNav' in './src'.
此组件文件肯定存在,并且包含在App.js文件中。我认为这可能与我的server.js文件有关。
const express = require("express");
const connectDB = require("./config/db");
const app = express();
const path = require("path");
connectDB();
app.use(express.json({ extended: false }));
// set the build directory as a static assets folder for express
app.use("/api/users", require("./routes/api/users"));
app.use("/api/auth", require("./routes/api/auth"));
app.use("/api/profile", require("./routes/api/profile"));
app.use("/api/lists", require("./routes/api/lists"));
app.use("/api/workflow", require("./routes/api/workflow"));
//redirect all of your server requests to /index.html
if (process.env.NODE_ENV === "production") {
//set static folder
app.use(express.static("client/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
有人知道出什么问题了吗?我经历了heroku的常见NodeJS问题,并尝试了所有问题。