Closed raphael10-collab closed 2 years ago
Hi @raphael10-collab, I just re-ran the example in a freshly initialized module (in a temporary directory), and it gave the correct expected output:
Hyperspace daemon connected, status:
{
apiVersion: '1.15.1',
holepunchable: false,
remoteAddress: '',
version: '3.19.0'
}
New drive created, key:
a9f9ac5c18cc1527741f677ba89f5095cf98ded36b60ba2dea1d68de2b1b24e4
readdir(/)
[ 'stuff', 'file1.txt' ]
readFile(/file1.txt, utf8)
Hello world!
readFile(/stuff/file2.bin, hex)
00010204
Shutting down Hyperspace, this may take a few seconds...
Are you sure you're not importing an old version of Hyperdrive?
Hi @andrewosh !
This is the content of my package.json
file :
{
"dependencies": {
"hyperdrive": "^10.21.0",
"hyperspace": "^3.19.0"
}
}
And this is the content of the hyperdrive_app.js
file :
// https://hypercore-protocol.org/guides/examples/hyperdrive-app/
const { Client, Server } = require('hyperspace')
const { Hyperdrive } = require('hyperdrive')
async function main () {
// Setup the Hyperspace Daemon connection
// =
const {client, cleanup} = await setupHyperspace()
console.log('Hyperspace daemon connected, status:')
console.log(await client.status())
// Create a Hyperdrive
// =
let drive = new Hyperdrive(client.corestore(), null)
await drive.promises.ready()
console.log('New drive created, key:')
console.log(' ', drive.key.toString('hex'))
// File writes
// =
await drive.promises.mkdir('/stuff')
await drive.promises.mkdir('/stuff/things')
await drive.promises.writeFile('/file1.txt', 'Hello world!')
await drive.promises.writeFile('/stuff/file2.bin', Buffer.from([0,1,2,4]))
// File reads
// =
console.log('readdir(/)')
console.log(' ', await drive.promises.readdir('/'))
console.log('readFile(/file1.txt, utf8)')
console.log(' ', await drive.promises.readFile('/file1.txt', 'utf8'))
console.log('readFile(/stuff/file2.bin, hex)')
console.log(' ', await drive.promises.readFile('/stuff/file2.bin', 'hex'))
// Swarm on the network
// =
await client.replicate(drive)
await new Promise(r => setTimeout(r, 3e3)) // just a few seconds
await client.network.configure(drive, {announce: false, lookup: false})
await cleanup()
}
async function setupHyperspace () {
let client
let server
try {
client = new Client()
await client.ready()
} catch (e) {
// no daemon, start it in-process
server = new Server()
await server.ready()
client = new Client()
await client.ready()
}
return {
client,
async cleanup () {
await client.close()
if (server) {
console.log('Shutting down Hyperspace, this may take a few seconds...')
await server.stop()
}
}
}
}
main()
node: v14.15.5 O.S. : Ubuntu 20.04 Desktop
This looks like it was caused by package-lock.json
, I think this should be resolved now. Try rm -rf node_modules && rm -rf package-lock.json && npm install
, the issue should be resolved but reopen if not.
Trying to execute this
demo app
: https://hypercore-protocol.org/guides/examples/hyperdrive-app/How to solve the problem?