【发布时间】:2019-02-20 11:59:23
【问题描述】:
我有一个 Vue CLI3 应用程序设置,当我使用 npm run serve 运行应用程序时它工作得非常好,但是,在运行 npm run build 以准备应用程序进行部署之后,当使用 Express 运行应用程序时,它给了我一个控制台错误提示 cannot set property render of undefined.. 这是我的应用程序根目录中的 server.js 文件设置
const express = require('express');
const path = require('path');
const serveStatic = require('serve-static');
let app = express();
app.use(serveStatic(__dirname + "/dist"));
const port = process.env.PORT || 5000;
app.get('*', (req, res) => {
res.sendFile(path.join( __dirname, './dist/index.html')); //path to index.html
});
app.listen(port, () => {
console.log('Listening on port ' + port)
});
【问题讨论】:
-
很高兴看到实际发生错误的代码
-
不太确定当错误实际发生时你的意思是什么,当我运行
node server.js时,错误会记录到浏览器的控制台中,所以我希望应用程序在给定的浏览器中呈现端口,实际上发生的是,就像我说的,`cannot set property render of undefined -
在错误中会有文件名和行号,因此您可以准确地看到错误发生的时间点
-
再次查看帖子,我添加了错误截图,提前感谢
-
那么你的错误发生在执行的浏览器部分,所以在你的客户端javascript代码的某个地方;您在此处发送的代码来自您的服务器端应用程序