我完成了我的 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}`));
我应该在哪里寻找问题?
经过大量调试后,我已将问题隔离到 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,问题就解决了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句