Closed cottrell closed 4 years ago
Hi @cottrell, are you getting this error?
If you're talking about this code here:
class NewPiecePlease {
constructor (Ipfs, OrbitDB) {
this.Ipfs = Ipfs
this.OrbitDB = OrbitDB
}
}
try {
const Ipfs = require('ipfs')
const OrbitDB = require('orbit-db')
module.exports = exports = new NewPiecePlease(Ipfs, OrbitDB)
} catch (e) {
window.NPP = new NewPiecePlease(window.Ipfs, window.OrbitDB)
}
The intention is that the browser will try to parse the try clause, find that require
is undefined, and failover to the catch clause.
If that's not happening let me know!
I coudl be wrong but I think "window" is not defined in node REPL.
Testing this:
npn init --yes
npm install orbit-db ipfs@^0.39.1
node
to open the REPLSeemed to work fine! Closing this for now but do let me know if your experience is different.
Did you hit the exception block though? You need to force it. Basically if you type "window" in node it shouldn't work I think.
Right but this code is specifically designed to differentiate between environments, essentially like an easy sniff. The idea is that you'd never hit the exception block in node, whereas you would in the browser and hit the catch block.
Should that be in there in the try/cache?:
https://github.com/orbitdb/field-manual/blob/master/01_Tutorial/01_Basics.md