Reactjs 未指定默认引擎,Heroku(MERN)中未提供扩展
所以我得到了我的MERN应用,我想上传到Heroku 一切正常,直到我访问我的Heroku应用程序URL并在日志中看到此错误:Reactjs 未指定默认引擎,Heroku(MERN)中未提供扩展,reactjs,heroku,deployment,internal-server-error,mern,Reactjs,Heroku,Deployment,Internal Server Error,Mern,所以我得到了我的MERN应用,我想上传到Heroku 一切正常,直到我访问我的Heroku应用程序URL并在日志中看到此错误:没有指定默认引擎,也没有提供扩展名 我会使用app.set('view engine','ejs')但我使用的是react-MERN Nodejs: const express = require('express'); const logger = require('morgan'); const passport = require('./passport/'); c
没有指定默认引擎,也没有提供扩展名
我会使用app.set('view engine','ejs')代码>但我使用的是react-MERN
Nodejs:
const express = require('express');
const logger = require('morgan');
const passport = require('./passport/');
const PORT = process.env.PORT || 8080;
const app = express();
const mongoose = require('mongoose');
mongoose.connect('mongodb', {useNewUrlParser: true})
const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
app.use(passport.initialize());
app.use(passport.session());
app.use(session({
resave: false,
saveUninitialized: false,
secret: 'secret here',
store: new MongoStore({ mongooseConnection: mongoose.connection })
}))
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use('/', indexRouter);
app.use('/authentication', usersRouter);
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'))
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "../client", "build", "index.html"))
})
}
app.listen(PORT);
module.exports = app
package.json:
{
"name": "name",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon app.js",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
}
}
}
有人知道如何解决这个问题吗
-多谢了,也许可以尝试使用res.sendFile(path.resolve(\uu dirname,“client”,“build”,“index.html”),因为使用\uu dirname会进入主目录我想你需要在你的包上写它。json如下:
{
"name": "name",
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": {
"node": "12.13.0",
"npm": "6.14.4"
},
"scripts": {
"start": "nodemon app.js",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
}
}
Replace node and npm with what you need and the same version you have in local.
显示您的nodejs服务器代码谢谢您的帮助哦不,我有一个上载时间冷却无法上载代码:(是
res.sendFile(path.resolve(uu dirname,“../client”,“build”,“index.html”)中的错误)
语句吗?什么意思?好的,我会尝试让您知道的!显示您的package.json