orbitdb / field-manual

The Offical User's Guide to OrbitDB
207 stars 43 forks source link

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in package.json #179

Open fabriziogianni7 opened 1 year ago

fabriziogianni7 commented 1 year ago

Hi, I'm using node v16, following the 1sts steps of the tutorial got this error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/fabri/keyko/orbit/node_modules/ipfs/package.json

my files: newpieceplease.js

class NewPiecePlease {
  constructor (Ipfs, OrbitDB) {
    this.OrbitDB = OrbitDB
    this.Ipfs = Ipfs
  }

  async create() {
    this.node = await this.Ipfs.create({
      preload: { enabled: false },
      repo: './ipfs',
      EXPERIMENTAL: { pubsub: true },
      config: {
        Bootstrap: [],
        Addresses: { Swarm: [] }
      }
    })

    this._init()
  }

  async _init () {
    this.orbitdb = await this.OrbitDB.createInstance(this.node)
    this.defaultOptions = { accessController: {
      write: [this.orbitdb.identity.id]
      }
    }
    if(this.onready) this.onready();
  }
}

try {
    // console.log('in try')
    const Ipfs = require('ipfs')
    const OrbitDB = require('orbit-db')

    module.exports = exports = new NewPiecePlease(Ipfs, OrbitDB)
} catch (e) {
    console.log(e)
    // window.NPP = new NewPiecePlease(window.Ipfs, window.OrbitDB)
}

main.js

const NPP = require('./newpieceplease') 

const main = async () => {
console.log(NPP)

}

main()
fabriziogianni7 commented 1 year ago

referencing this issue from ipfs repo -- > https://github.com/ipfs/js-ipfs/issues/4139

changing my file this way:

newpieceplease_v2

 // i just need it in nodejs so don't care about browser part
export default class NewPiecePlease {
  constructor(Ipfs, OrbitDB) {
    this.OrbitDB = OrbitDB
    this.Ipfs = Ipfs
  }

  async create() {
    this.node = await this.Ipfs.create({
      preload: { enabled: false },
      repo: './ipfs',
      EXPERIMENTAL: { pubsub: true },
      config: {
        Bootstrap: [],
        Addresses: { Swarm: [] }
      }
    })

    this._init()
  }

  async _init() {
    this.orbitdb = await this.OrbitDB.createInstance(this.node)
    this.defaultOptions = {
      accessController: {
        write: [this.orbitdb.identity.id]
      }
    }
    if (this.onready) this.onready();
  }
}

main.js:

iimport NewPiecePlease from './newpieceplease_v2.js'
import * as Ipfs from 'ipfs'
import OrbitDB from 'orbit-db'

const main = async () => {
    try {
        const NPP = new NewPiecePlease(Ipfs, OrbitDB)
        await NPP.create()

        NPP.onready = () => console.log(NPP.orbitdb.identity.id)

    } catch (error) {
        console.log(error)
    }
}

main()
fabriziogianni7 commented 1 year ago

let me know any thought thanks !