You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native非组件类报错:Cannot call a class as a function

解决React Native中"Cannot call a class as a function"报错

你的问题根源不在WebCrawler类的实例化方式(你在App.js里用new WebCrawler()是完全正确的),也和WebCrawler是否继承Component无关——问题出在Crawler.js内部的类初始化代码里:

看你的WebCrawler类定义:

export class WebCrawler {
  cookie_stores = [CookieStore(sisgrad_domain)];
  ...
}

这里的CookieStore(sisgrad_domain)是直接把CookieStore类当作普通函数调用了,但CookieStore本身应该是一个需要实例化的类,必须用new关键字来创建它的实例。

修复方法

修改Crawler.js里的cookie_stores初始化代码,给CookieStore加上new关键字:

export class WebCrawler {
  cookie_stores = [new CookieStore(sisgrad_domain)];
  ...
}

这样就能正确实例化CookieStore类,避免"Cannot call a class as a function"的报错了。

内容的提问来源于stack exchange,提问作者user6791424

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:07:05