开发者社区> 问答> 正文

帮忙看下阿里云OpenAPI ,TypeScript的代码在nodejs里面运行报错是什么原因?

帮忙看下阿里云OpenAPI ,TypeScript的代码在nodejs里面运行报错是什么原因?
TypeError: http.Agent is not a constructor
./node_modules/httpx/lib/index.js
http://localhost:8000/mf-dep____vendor.82a2e712.js:275578:19
webpack_require
http://localhost:8000/mf-va_remoteEntry.js:878:42
./node_modules/@alicloud/tea-typescript/dist/tea.js
http://localhost:8000/mf-dep____vendor.82a2e712.js:36821:26
webpack_require
http://localhost:8000/mf-va_remoteEntry.js:878:42
./node_modules/@alicloud/tea-util/dist/client.js
http://localhost:8000/mf-dep____vendor.82a2e712.js:37307:27
webpack_require
http://localhost:8000/mf-va_remoteEntry.js:878:42
./node_modules/@alicloud/facebody20191230/dist/client.js
http://localhost:8000/mf-dep____vendor.82a2e712.js:10314:33
webpack_require
http://localhost:8000/mf-va_remoteEntry.js:878:42
./nodemodules/.cache/mfsu/mf-va@alicloud_facebody20191230.js
http://localhost:8000/mf-dep____vendor.82a2e712.js:11:129
webpack_require
http://localhost:8000/mf-va_remoteEntry.js:878:42
(anonymous function)
http://localhost:8000/mf-va_remoteEntry.js:826:333
webpack_require.m.
webpack:/ant-design-pro/webpack/runtime/remotes loading:1687
1684 | var onFactory = function(factory) {
1685 | data.p = 1;
1686 | webpack_require.m[id] = function(module) {

1687 | module.exports = factory();
| ^ 1688 | }
1689 | };
1690 | handleFunction(webpack_require, data[2], 0, 0, onExternal, 1);
View compiled
options.factory
webpack:/ant-design-pro/webpack/runtime/react refresh:6
3 | options.factory = function (moduleObject, moduleExports, webpackRequire) {
4 | webpack_require.$Refresh$.setup(options.id);
5 | try {
6 | originalFactory.call(this, moduleObject, moduleExports, webpackRequire);
| ^ 7 | } finally {
8 | if (typeof Promise !== 'undefined' && moduleObject.exports instanceof Promise) {
9 | options.module.exports = options.module.exports.then(
View compiled
webpack_require
.ant-design-pro/webpack/bootstrap:24
21 | var execOptions = { id: moduleId, module: module, factory: webpack_modules[moduleId], require: webpack_require };
22 | webpack_require.i.forEach(function(handler) { handler(execOptions); });
23 | module = execOptions.module;
24 | execOptions.factory.call(module.exports, module, module.exports, execOptions.require);
| ^ 25 | } catch(e) {
26 | module.error = e;
27 | throw e;
View compiled
▶ 3 stack frames were collapsed.
webpack_require
.ant-design-pro/webpack/bootstrap:24
21 | var execOptions = { id: moduleId, module: module, factory: webpack_modules[moduleId], require: webpack_require };
22 | webpack_require.i.forEach(function(handler) { handler(execOptions); });
23 | module = execOptions.module;
24 | execOptions.factory.call(module.exports, module, module.exports, execOptions.require);
| ^ 25 | } catch(e) {
26 | module.error = e;
27 | throw e;
View compiled
▶ 3 stack frames were collapsed.
webpack_require
.ant-design-pro/webpack/bootstrap:24
21 | var execOptions = { id: moduleId, module: module, factory: webpack_modules[moduleId], require: webpack_require };
22 | webpack_require.i.forEach(function(handler) { handler(execOptions); });
23 | module = execOptions.module;
24 | execOptions.factory.call(module.exports, module, module.exports, execOptions.require);
| ^ 25 | } catch(e) {
26 | module.error = e;
27 | throw e;
View compiled
Function.fn
webpack:/ant-design-pro/webpack/runtime/hot module replacement:62
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error. Click the 'X' or hit ESC to dismiss this message.

展开
收起
真的很搞笑 2024-03-19 13:49:56 213 0
3 条回答
写回答
取消 提交回答
  • 我也遇到这种情况,解决了吗兄弟?

    2024-08-15 19:58:41
    赞同 展开评论 打赏
  • 不支持前端执行 ,此回答整理自钉群“OpenAPI 开发者门户 - 值班服务群2群”

    2024-03-19 20:35:25
    赞同 展开评论 打赏
  • 报错信息表明,在使用TypeScript编写的阿里云OpenAPI代码在Node.js环境中运行时出现了TypeError: http.Agent is not a constructor错误。这很可能是因为使用的http客户端模块httpx在当前环境下找不到http.Agent构造函数。一种可能的原因是Node.js版本过低,因为http.Agent是在较新版本中引入的类。确保您的Node.js环境至少是支持http.Agent的版本(比如≥10.x)。另外,请检查httpx库及其依赖包是否正确安装,并兼容所用Node.js版本。如果仍有问题,请考虑降级或替换不兼容的http客户端库。

    2024-03-19 16:42:33
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
探究 Node.js 的服务端之路 立即下载
个推微服务实践 基于OpenResty 和Node.js 立即下载
沪江基于Node.js大规模应用实践 立即下载