RSocketTcpClient 不是构造函数 - 带有 Rsocket-js 的 NodeJS
RSocketTcpClient is not a constructor - NodeJS with Rsocket-js
我想 运行 使用 Rsocket 指南中的简单示例在 NodeJs 上使用 Rsocket TCP 客户端(https://rsocket.io/guides/rsocket-js/client/rsocket-tcp-client):
async function createClient(options) {
const client = new RSocketClient({
setup: {
dataMimeType: 'text/plain',
keepAlive: 1000000, // avoid sending during test
lifetime: 100000,
metadataMimeType: 'text/plain',
},
transport: new RSocketTCPClient({
host: options.host,
port: options.port,
}),
});
return await client.connect();
}
async function run() {
const rsocket = await createClient({
host: '127.0.0.1',
port: 9898,
});
}
await run();
但是当我尝试通过 node app.js
运行 应用程序时出现错误:
TypeError: RSocketTcpClient is not a constructor
。
我检查了 RSocketTcpClient
的实现,看起来有构造函数:
export class RSocketTcpClient extends RSocketTcpConnection {
constructor(options: net.TcpSocketConnectOpts, encoders?: Encoders<any>);
connect(): void;
}
谁能告诉我哪里出了问题?我正在使用简单的 package.json:
{
"name": "rsocket-example",
"private": true,
"description": "RSocket example",
"version": "0.0.27",
"repository": {
"type": "git",
"url": "https://github.com/rsocket/rsocket-js.git"
},
"type": "module",
"dependencies": {
"rsocket-core": "^0.0.27",
"rsocket-flowable": "^0.0.27",
"rsocket-tcp-server": "^0.0.27",
"rsocket-types": "^0.0.27",
"rsocket-websocket-client": "^0.0.27",
"rsocket-websocket-server": "^0.0.27"
}
}
这里的源项目rsocket-js似乎蒸腾配置错误,让默认导出 RSocketTCPClient
class 声明在 default
变量下。
您的解决方法是调整您自己项目中的转译器配置,或者仅使用 default
导出的对象,如下所示:
// instead of new RSocketTCPClient()
new RSocketTCPClient.default({
host: options.host,
port: options.port,
});
我想 运行 使用 Rsocket 指南中的简单示例在 NodeJs 上使用 Rsocket TCP 客户端(https://rsocket.io/guides/rsocket-js/client/rsocket-tcp-client):
async function createClient(options) {
const client = new RSocketClient({
setup: {
dataMimeType: 'text/plain',
keepAlive: 1000000, // avoid sending during test
lifetime: 100000,
metadataMimeType: 'text/plain',
},
transport: new RSocketTCPClient({
host: options.host,
port: options.port,
}),
});
return await client.connect();
}
async function run() {
const rsocket = await createClient({
host: '127.0.0.1',
port: 9898,
});
}
await run();
但是当我尝试通过 node app.js
运行 应用程序时出现错误:
TypeError: RSocketTcpClient is not a constructor
。
我检查了 RSocketTcpClient
的实现,看起来有构造函数:
export class RSocketTcpClient extends RSocketTcpConnection {
constructor(options: net.TcpSocketConnectOpts, encoders?: Encoders<any>);
connect(): void;
}
谁能告诉我哪里出了问题?我正在使用简单的 package.json:
{
"name": "rsocket-example",
"private": true,
"description": "RSocket example",
"version": "0.0.27",
"repository": {
"type": "git",
"url": "https://github.com/rsocket/rsocket-js.git"
},
"type": "module",
"dependencies": {
"rsocket-core": "^0.0.27",
"rsocket-flowable": "^0.0.27",
"rsocket-tcp-server": "^0.0.27",
"rsocket-types": "^0.0.27",
"rsocket-websocket-client": "^0.0.27",
"rsocket-websocket-server": "^0.0.27"
}
}
这里的源项目rsocket-js似乎蒸腾配置错误,让默认导出 RSocketTCPClient
class 声明在 default
变量下。
您的解决方法是调整您自己项目中的转译器配置,或者仅使用 default
导出的对象,如下所示:
// instead of new RSocketTCPClient()
new RSocketTCPClient.default({
host: options.host,
port: options.port,
});