ipfs / ipfs/helia

Attempted import error: 'RTCSessionDescription' is not exported

Open
#553 7 comments 0 reactions 0 assignees View on GitHub
kind/discussion kind/support need/analysis
Dominant language
TypeScript
Stars
1.3k
Forks
159
Avg merge
2h 11m
Merged PRs (30d)
16

Description

I have no luck writing a ReactJS Hook for Helia. I keep getting the following errors... Any thoughts?

Repro(s)
1. Start a new NextJS project
2. Add Helia
3. copy & paste hooks below.
4. Use it in any react component

// version
"helia": "4.2.3",
"next": "14.2.3",

Error
```
⨯ ../../node_modules/.pnpm/@libp2p+webrtc@4.0.33_react-native@0.74.1/node_modules/@libp2p/webrtc/dist/src/private-to-private/initiate-connection.js
Attempted import error: 'RTCSessionDescription' is not exported from '../webrtc/index.js' (imported as 'RTCSessionDescription').
```

Sample Codes
```
import { json } from "@helia/json";
import { Helia, createHelia } from "helia";
import { useCallback, useEffect, useState } from "react";

export type HeliaJsonResult = {
helia: Helia | null;
nodeId: string | null;
nodeIsOnline: boolean;
addJson: (jsonData: any) => Promise;
getJson: (cid: string) => Promise;
error: Error | null;
loading: boolean;
};

export const useHeliaJson = (): HeliaJsonResult => {
const [helia, setHelia] = useState(null);
const [nodeId, setNodeId] = useState(null);
const [nodeIsOnline, setNodeIsOnline] = useState(false);
const [error, setError] = useState(null);
const [loading, setLoading] = useState(true);

useEffect(() => {
const init = async () => {
try {
const heliaInstance = await createHelia();
setHelia(heliaInstance);

console.log("Helia instance: ", heliaInstance);

const nodeId = heliaInstance.libp2p.peerId.toString();
const nodeIsOnline = heliaInstance.libp2p.status === "started";
setNodeId(nodeId);
setNodeIsOnline(nodeIsOnline);

setLoading(false);
} catch (err) {
setError(err as Error);
setLoading(false);
}
};

init();
}, []);

const addJson = useCallback(
async (jsonData: any): Promise => {
if (!helia) {
throw new Error("Helia instance is not initialized");
}
try {
const cid = await json(helia).add(jsonData);
return cid.toString();
} catch (err) {
setError(err as Error);
throw err;
}
},
[helia]
);

const getJson = useCallback(
async (cid: string): Promise => {
if (!helia) {
throw new Error("Helia instance is not initialized");
}
try {
const data = await json(helia).get(cid as any);
return data;
} catch (err) {
setError(err as Error);
throw err;
}
},
[helia]
);

return {
helia,
nodeId,
nodeIsOnline,
addJson,
getJson,
error,
loading,
};
};

export default useHeliaJson;

``

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.