【问题标题】:A deployed Heroku app works online only on the PC I deployed it from已部署的 Heroku 应用程序只能在我部署它的 PC 上在线运行
【发布时间】:2019-10-01 00:43:42
【问题描述】:

我完成了我的 MERN 堆栈应用程序并将其部署到 Heroku。在 Heroku 上打开它,它工作。有趣的是,它在我部署它的机器之外的任何其他机器上都不起作用。 在任何其他机器上打开时,它只是进入空白屏幕并在控制台中显示以下错误:

redux.js:575 Uncaught TypeError: Cannot read property 'apply' of undefined
    at redux.js:575
    at u (redux.js:79)
    at Module.102 (store.js:9)
    at f ((index):1)
    at Object.57 (spinner.gif:1)
    at f ((index):1)
    at a ((index):1)
    at Array.e [as push] ((index):1)
    at main.4febefcb.chunk.js:1

我正在尝试找出导致此行为的可能原因。

我已经尝试创建一个新的 Heroku 应用并重新部署它,重新启动 dynos 并检查我的 server.js 配置中的端口。

//static assets for production
if (process.env.NODE_ENV === "production") {
  //set a 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 is being ran on port ${PORT}`));

我应该在哪里查找问题?

【问题讨论】:

  • 能否请您发布部署 URL 以便其他人可以查看?
  • 另外,“不能在任何其他机器上工作”是什么意思? HTTP 404? 500? 200但是黑屏?你的控制台有什么东西吗?服务器端日志?如果您不向我们提供任何信息,我们将无法进行故障排除。见How to Ask
  • 添加了我错过的所有信息。

标签: node.js reactjs mongodb express heroku


【解决方案1】:

经过大量调试,我已将问题隔离到 Redux 开发工具。该应用适用于任何安装了 Redux 开发工具的浏览器。

我发现它与 store.js 文件有关,并检查了我的 createStore:

 const store = createStore(
  rootReducer,
  initialState,
  compose(
    applyMiddleware(...middleware),
    window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
  )
);

从 compose 中删除以下行后

窗口。REDUX_DEVTOOLS_EXTENSION && REDUX_DEVTOOLS_EXTENSION()

我把它推送到 Heroku,问题就解决了。

【讨论】:

  • 您需要维护开发和生产环境,并有条件地在每个环境中分别添加或删除devtools。
猜你喜欢
  • 2022-07-15
  • 1970-01-01
  • 2022-12-10
  • 2016-10-10
  • 2016-09-22
  • 2016-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多