IPFS 不是构造函数:Nodejs - IPFS/OrbitDB 聊天室
IPFS is not a constructor: Nodejs - IPFS/OrbitDB chatroom
我正在尝试使用 Nodejs 构建一个 Dapp,并且 IPFS/OrbitDB 每次我尝试启动我的应用程序时我都收到错误消息:
this.node = 新 IPFS({
^
类型错误:IPFS 不是构造函数
这是我没有特定 Swarm 的基本代码:
const Ipfs = require('ipfs');
const OrbitDB = require('orbit-db');
class chatroom {
constructor(IPFS, OrbitDB) {
this.OrbitDB = OrbitDB;
this.node = new IPFS({
preload: {enable: false},
repo: "./ipfs",
EXPERIMENTAL: {pubsub: true},
config: {
Bootstrap: [],
Addresses: {Swarm: []}
}
});
this.node.on("error", (e) => {throw (e)});
this.node.on("ready", this._init.bind(this));
}
async _init(){
this.orbitdb = await this.OrbitDB.createInstance(this.node);
this.onready();
}
}
module.exports = exports = new chatroom(Ipfs, OrbitDB);
我 运行 使用以下版本的 IPFS:ipfs@0.42.0
我也在一个空的 Nodejs 应用程序上尝试过,当我添加一个特定的 Swarm 进行连接时,我也遇到了同样的错误。
非常感谢您的帮助,感谢您提前抽出时间。
亲切的问候
贝尼
我现在是这样做的:
const IPFS = require('ipfs');
async function createNode() {
let node = await IPFS.create(
{
repo: (() => `repo-${Math.random()}`)(),
"Addresses": {
"Swarm": [
"/ip4/0.0.0.0/tcp/4001"
],
"API": "/ip4/127.0.0.1/tcp/5001",
"Gateway": "/ip4/127.0.0.1/tcp/8080"
}
}
);
try {
await node.start();
console.log('Node started!');
} catch (error) {
console.error('Node failed to start!', error);
}
}
(谢谢@Eugene)
我正在尝试使用 Nodejs 构建一个 Dapp,并且 IPFS/OrbitDB 每次我尝试启动我的应用程序时我都收到错误消息:
this.node = 新 IPFS({ ^
类型错误:IPFS 不是构造函数
这是我没有特定 Swarm 的基本代码:
const Ipfs = require('ipfs');
const OrbitDB = require('orbit-db');
class chatroom {
constructor(IPFS, OrbitDB) {
this.OrbitDB = OrbitDB;
this.node = new IPFS({
preload: {enable: false},
repo: "./ipfs",
EXPERIMENTAL: {pubsub: true},
config: {
Bootstrap: [],
Addresses: {Swarm: []}
}
});
this.node.on("error", (e) => {throw (e)});
this.node.on("ready", this._init.bind(this));
}
async _init(){
this.orbitdb = await this.OrbitDB.createInstance(this.node);
this.onready();
}
}
module.exports = exports = new chatroom(Ipfs, OrbitDB);
我 运行 使用以下版本的 IPFS:ipfs@0.42.0
我也在一个空的 Nodejs 应用程序上尝试过,当我添加一个特定的 Swarm 进行连接时,我也遇到了同样的错误。
非常感谢您的帮助,感谢您提前抽出时间。
亲切的问候
贝尼
我现在是这样做的:
const IPFS = require('ipfs');
async function createNode() {
let node = await IPFS.create(
{
repo: (() => `repo-${Math.random()}`)(),
"Addresses": {
"Swarm": [
"/ip4/0.0.0.0/tcp/4001"
],
"API": "/ip4/127.0.0.1/tcp/5001",
"Gateway": "/ip4/127.0.0.1/tcp/8080"
}
}
);
try {
await node.start();
console.log('Node started!');
} catch (error) {
console.error('Node failed to start!', error);
}
}
(谢谢@Eugene)