帮忙看下阿里云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.
报错信息表明,在使用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客户端库。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。