Chrome 我得到一个TypeError:无法读取未定义的属性(阅读“includes”)

wmtdaxz3  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(152)

我创建了这个项目,使用React-Vite作为前端,Node作为后端。在本地模式下工作,一切正常,但是当我进入Vercel部署的版本时,我得到了这个错误,网页将无法加载。
有趣的是,我只得到这个错误时,使用Chrome和从我的笔记本电脑。如果我使用Edge访问URL一切顺利,如果我在移动的手机中使用Chrome也是如此。整个错误消息是这样的:类型错误:无法读取位于$J(index-3741cc67.js:321:32421)at ab(index-3741cc67.js:三十八:19538)在Jg(index-3741cc67.js:四十:3139)(索引-3741cc67.js:四十:44830)在xL(index-3741cc67.js:四十:39787)(index-3741cc67.js:四十:39715)在MH(index-3741cc67.js:四十:39568)在c0(index-3741cc67.js:四十:35933)(index-3741cc67.js:四十:36737)在Aa(index-3741cc67.js:三十八:(3279)
知道为什么会这样吗提前感谢!
到目前为止,我还没有尝试过任何东西,因为我没有从错误消息中得到任何问题来自哪里的线索。ChatGPT没有帮助LOL

c0vxltue

c0vxltue1#

我找到了解决方案,问题出在这个函数上:

const { isFavorite, handleFavorites, showFavorite } = useFavorites(
    user?.favorites.includes(evento._id) || false,
    evento ? evento._id : null,
    user ? user._id : null
  );

当我在favorites和evento中添加问号时,错误就消失了:

const { isFavorite, handleFavorites, showFavorite } = useFavorites(
    user?.favorites?.includes(evento?._id) || false,
    evento ? evento._id : null,
    user ? user._id : null
  );

相关问题