首页 > 解决方案 > heroku deploy vue app TypeError: Object prototype may only be an Object or null: /dist/

问题描述

这个问题让我发疯。

TypeError: Object prototype may only be an Object or null: /dist/

我认为 heroku 失败是由于静态服务问题,因为我正在使用由快速服务器提供的单页 vue 应用程序。我不确定这个错误是什么意思?它似乎在引用 app.use(express.static(__dirname, '/dist/')); 但我不知道除了路径之外要给出什么论据?

我的 express server.js 非常简单:

const express = require('express');

const app = express();
app.use(express.static(__dirname, '/dist/'));

app.get(/.*/, function(req, res){
    res.sendfile(__dirname + "/dist/index.html")
})

const port = process.env.PORT || 5000;
app.listen(port);

这是我的一些heroku日志,详细说明了问题

2020-06-09T07:47:19.000000+00:00 app[api]: Build started by user luthertester@gmail.com
2020-06-09T07:48:47.890090+00:00 heroku[web.1]: State changed from crashed to starting
2020-06-09T07:48:47.712078+00:00 app[api]: Deploy d457ea7c by user luthertester@gmail.com
2020-06-09T07:48:47.712078+00:00 app[api]: Release v21 created by user luthertester@gmail.com
2020-06-09T07:48:55.749555+00:00 heroku[web.1]: Starting process with command `npm start`
2020-06-09T07:48:58.279945+00:00 heroku[web.1]: Process exited with status 1
2020-06-09T07:48:58.325770+00:00 heroku[web.1]: State changed from starting to crashed
2020-06-09T07:48:58.027989+00:00 app[web.1]: 
2020-06-09T07:48:58.028015+00:00 app[web.1]: > devdeepblog@0.1.0 start /app
2020-06-09T07:48:58.028016+00:00 app[web.1]: > node server.js
2020-06-09T07:48:58.028016+00:00 app[web.1]: 
2020-06-09T07:48:58.213348+00:00 app[web.1]: /app/node_modules/serve-static/index.js:48
2020-06-09T07:48:58.213349+00:00 app[web.1]:   var opts = Object.create(options || null)
2020-06-09T07:48:58.213350+00:00 app[web.1]:                     ^
2020-06-09T07:48:58.213350+00:00 app[web.1]: 
2020-06-09T07:48:58.213351+00:00 app[web.1]: TypeError: Object prototype may only be an Object or null: /dist/
2020-06-09T07:48:58.213351+00:00 app[web.1]:     at Function.create (<anonymous>)
2020-06-09T07:48:58.213352+00:00 app[web.1]:     at Function.serveStatic [as static] (/app/node_modules/serve-static/index.js:48:21)
2020-06-09T07:48:58.213353+00:00 app[web.1]:     at Object.<anonymous> (/app/server.js:4:23)
2020-06-09T07:48:58.213353+00:00 app[web.1]:     at Module._compile (module.js:652:30)
2020-06-09T07:48:58.213353+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:663:10)
2020-06-09T07:48:58.213354+00:00 app[web.1]:     at Module.load (module.js:565:32)
2020-06-09T07:48:58.213354+00:00 app[web.1]:     at tryModuleLoad (module.js:505:12)
2020-06-09T07:48:58.213354+00:00 app[web.1]:     at Function.Module._load (module.js:497:3)
2020-06-09T07:48:58.213355+00:00 app[web.1]:     at Function.Module.runMain (module.js:693:10)
2020-06-09T07:48:58.213355+00:00 app[web.1]:     at startup (bootstrap_node.js:191:16)
2020-06-09T07:48:58.218237+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-06-09T07:48:58.218654+00:00 app[web.1]: npm ERR! errno 1
2020-06-09T07:48:58.219698+00:00 app[web.1]: npm ERR! devdeepblog@0.1.0 start: `node server.js`
2020-06-09T07:48:58.219855+00:00 app[web.1]: npm ERR! Exit status 1
2020-06-09T07:48:58.220093+00:00 app[web.1]: npm ERR! 
2020-06-09T07:48:58.220259+00:00 app[web.1]: npm ERR! Failed at the devdeepblog@0.1.0 start script.
2020-06-09T07:48:58.220430+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-06-09T07:48:58.226320+00:00 app[web.1]: 
2020-06-09T07:48:58.226466+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-06-09T07:48:58.226574+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-06-09T07_48_58_221Z-debug.log

标签: node.jsvue.jsheroku

解决方案


推荐阅读