Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

TypeError: Cannot read property 'PrivKey' of undefined && Uncaught Error: Callback was already called. #963

Closed
metal-young opened this issue Aug 26, 2017 · 6 comments
Labels
env:Safari status/ready Ready to be worked

Comments

@metal-young
Copy link

  • Version:
    js-ipfs version: 0.25.1

  • Platform:
    Darwin localhost 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64

  • Subsystem:

Type:

Bug

Severity:

High

Description:

init local jsipfs repo

and then init ipfs

BUT

Console ->

pre-start.js:19 Uncaught TypeError: Cannot read property 'PrivKey' of undefined
    at waterfall (pre-start.js:19)
    at nextTask (waterfall.js:16)
    at next (waterfall.js:23)
    at onlyOnce.js:12
    at store.get (config.js:45)
    at levelup.js:211
    at IDBRequest.req.onsuccess (index.js:125)
waterfall @ pre-start.js:19
nextTask @ waterfall.js:16
next @ waterfall.js:23
(anonymous) @ onlyOnce.js:12
store.get @ config.js:45
(anonymous) @ levelup.js:211
req.onsuccess @ index.js:125
IndexedDB (async)
Level._get @ index.js:101
AbstractLevelDOWN.get @ abstract-leveldown.js:94
LevelUP.get @ levelup.js:195
get @ index.js:42
get @ config.js:32
waterfall @ pre-start.js:17
nextTask @ waterfall.js:16
exports.default @ waterfall.js:26
(anonymous) @ pre-start.js:16
series @ boot.js:31
(anonymous) @ parallel.js:31
replenish @ eachOfLimit.js:64
iterateeCallback @ eachOfLimit.js:49
(anonymous) @ onlyOnce.js:12
(anonymous) @ parallel.js:36
waterfall @ index.js:123
(anonymous) @ once.js:12
next @ waterfall.js:21
(anonymous) @ onlyOnce.js:12
waterfall @ index.js:110
nextTask @ waterfall.js:16
next @ waterfall.js:23
(anonymous) @ onlyOnce.js:12
waterfall @ index.js:105
nextTask @ waterfall.js:16
next @ waterfall.js:23
(anonymous) @ onlyOnce.js:12
maybeWithSharding @ blockstore.js:37
setImmediate @ blockstore.js:46
(anonymous) @ setImmediate.js:27
Item.run @ browser.js:153
drainQueue @ browser.js:123
setTimeout (async)
runTimeout @ browser.js:41
process.nextTick @ browser.js:143
(anonymous) @ setImmediate.js:26
exports.lock @ lock-memory.js:31
waterfall @ index.js:87
nextTask @ waterfall.js:16
next @ waterfall.js:23
(anonymous) @ onlyOnce.js:12
parallel @ index.js:151
(anonymous) @ parallel.js:39
(anonymous) @ once.js:12
iterateeCallback @ eachOfLimit.js:47
(anonymous) @ onlyOnce.js:12
(anonymous) @ parallel.js:36
get @ version.js:59
store.get @ version.js:31
(anonymous) @ levelup.js:211
req.onsuccess @ index.js:125
IndexedDB (async)
Level._get @ index.js:101
AbstractLevelDOWN.get @ abstract-leveldown.js:94
LevelUP.get @ levelup.js:195
get @ index.js:42
get @ version.js:27
check @ version.js:51
version @ index.js:140
(anonymous) @ parallel.js:31
replenish @ eachOfLimit.js:64
(anonymous) @ eachOfLimit.js:68
eachOfLimit @ eachOfLimit.js:39
(anonymous) @ doLimit.js:9
exports.default @ eachOf.js:9
_parallel @ parallel.js:30
parallelLimit @ parallel.js:88
_isInitialized @ index.js:137
waterfall @ index.js:86
nextTask @ waterfall.js:16
next @ waterfall.js:23
(anonymous) @ onlyOnce.js:12
(anonymous) @ index.js:203
(anonymous) @ levelup.js:100
g @ events.js:165
EventEmitter.emit @ events.js:78
(anonymous) @ levelup.js:123
(anonymous) @ abstract-leveldown.js:42
onsuccess @ index.js:88
req.onsuccess @ index.js:40
IndexedDB (async)
Level._open @ index.js:37
AbstractLevelDOWN.open @ abstract-leveldown.js:36
LevelUP.open @ levelup.js:115
LevelUP @ levelup.js:84
LevelUP @ levelup.js:45
LevelDatastore @ index.js:27
createBackend @ backends.js:6
IpfsRepo @ index.js:46
module.exports @ repo-browser.js:7
IPFS @ index.js:45
1002.ipfs @ app.js:30
s @ _prelude.js:1
e @ _prelude.js:1
(anonymous) @ _prelude.js:1
onlyOnce.js:9 Uncaught Error: Callback was already called.
    at onlyOnce.js:9
    at store.get (config.js:33)
    at dispatchError (util.js:22)
    at levelup.js:203
    at IDBTransaction.tx.onabort (index.js:104)

Steps to reproduce the error:

code:

/src/app.js

const  IPFS = require('ipfs')

const Repo = require('ipfs-repo')

const  repo_path = "/Users/xiaoyu/.jsipfs"
const repo = new Repo(repo_path)


repo.init({ cool: 'config' }, (err) => {
    if (err) {
        throw err
    }

    repo.open((err) => {
        if (err) {
            throw err
        }

        console.log('repo is ready')
    })
})

const ipfs = new IPFS(
    {
        repo:repo_path,


        start: true,
        EXPERIMENTAL:{
            pubsub:true
        }

    }
)

package.json

{
  "name": "ipfs-pubsub-chat",
  "version": "0.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "http-server -c-1 -p 12321 public",
    "compile": "browserify src/app.js -o public/js/app.js -d"
  },
  "author": "xiaoyu",
  "license": "ISC",
  "dependencies": {
    "browserify": "^14.4.0",
    "datastore-level": "^0.6.0",
    "http-server": "^0.10.0",
    "ipfs": "^0.25.2",
    "ipfs-repo": "^0.17.0"
  }
}

commands

xiaoyu@localhost.com➤ npm start

> ipfs-pubsub-chat@0.0.1 start /Users/xiaoyu/ipfs_projects/ipfs-pubsub-chat
> http-server -c-1 -p 12321 public

Starting up http-server, serving public
Available on:
  http://127.0.0.1:12321
  http://192.168.0.104:12321
Hit CTRL-C to stop the server
[Sun Aug 27 2017 03:20:14 GMT+0800 (CST)] "GET /" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36"
[Sun Aug 27 2017 03:20:14 GMT+0800 (CST)] "GET /js/app.js" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36"






xiaoyu@localhost.com➤ npm run compile

> ipfs-pubsub-chat@0.0.1 compile /Users/xiaoyu/ipfs_projects/ipfs-pubsub-chat
> browserify src/app.js -o public/js/app.js -d

@daviddias
Copy link
Member

I believe there is some confusion on this test, let me try to break it down from what I can understand reading the info you shared. Btw, thank you for sharing all the steps!

a) You don't need to bring the repo module up

All you need is just to do:

const  IPFS = require('ipfs')
const  repo_path = "/Users/xiaoyu/.jsipfs"

const ipfs = new IPFS({
  repo: repo_path,
  EXPERIMENTAL: {
    pubsub: true
  }
})

b) If you are looking to run this application on the browser, the path has no meaning with regards to your fs

This might be confusing but essentially a Browser has no access to the local file system, it uses its own sandboxed datastore (LocalStorage or IndexedDB).

This means that you can even simplify more your app.js to just:

const  IPFS = require('ipfs')

const ipfs = new IPFS({
  EXPERIMENTAL: {
    pubsub: true
  }
})

Try it again with this latest node set up and let me know how it went :)

@metal-young
Copy link
Author

thank you for your help. I tried both the a and b methods. The browser's console produces the same error.

rsa-browser.js:11 Uncaught TypeError: Cannot read property 'generateKey' of undefined
    at Object.exports.generateKey (rsa-browser.js:11)
    at Object.generateKeyPair (rsa-class.js:112)
    at Object.exports.generateKeyPair (index.js:33)
    at waterfall (index.js:138)
    at nextTask (waterfall.js:16)
    at exports.default (waterfall.js:26)
    at Function.exports.create (index.js:137)
    at waterfall (init.js:52)
    at nextTask (waterfall.js:16)
    at next (waterfall.js:23)
exports.generateKey @ rsa-browser.js:11
generateKeyPair @ rsa-class.js:112
exports.generateKeyPair @ index.js:33
waterfall @ index.js:138
nextTask @ waterfall.js:16
exports.default @ waterfall.js:26
exports.create @ index.js:137
waterfall @ init.js:52
nextTask @ waterfall.js:16
next @ waterfall.js:23
(anonymous) @ onlyOnce.js:12
db.get @ index.js:49
dispatchError @ util.js:22
(anonymous) @ levelup.js:203
req.onsuccess @ index.js:128
IndexedDB (async)
Level._get @ index.js:101
AbstractLevelDOWN.get @ abstract-leveldown.js:94
LevelUP.get @ levelup.js:195
has @ index.js:46
exists @ version.js:18
exists @ index.js:195
waterfall @ init.js:42
nextTask @ waterfall.js:16
exports.default @ waterfall.js:26
promisify @ init.js:40
(anonymous) @ index.js:32
tasks.push @ boot.js:73
(anonymous) @ parallel.js:31
replenish @ eachOfLimit.js:64
(anonymous) @ eachOfLimit.js:68
eachOfLimit @ eachOfLimit.js:39
(anonymous) @ doLimit.js:9
_parallel @ parallel.js:30
series @ series.js:83
maybeOpenRepo @ boot.js:108
series @ boot.js:47
(anonymous) @ parallel.js:39
(anonymous) @ once.js:12
iterateeCallback @ eachOfLimit.js:44
(anonymous) @ onlyOnce.js:12
(anonymous) @ parallel.js:36
waterfall @ index.js:123
(anonymous) @ once.js:12
next @ waterfall.js:21
(anonymous) @ onlyOnce.js:12
parallel @ index.js:145
(anonymous) @ parallel.js:39
(anonymous) @ once.js:12
iterateeCallback @ eachOfLimit.js:44
(anonymous) @ onlyOnce.js:12
(anonymous) @ parallel.js:36
get @ version.js:53
store.get @ version.js:29
dispatchError @ util.js:22
(anonymous) @ levelup.js:203
req.onsuccess @ index.js:128
IndexedDB (async)
Level._get @ index.js:101
AbstractLevelDOWN.get @ abstract-leveldown.js:94
LevelUP.get @ levelup.js:195
get @ index.js:42
get @ version.js:27
check @ version.js:51
version @ index.js:140
(anonymous) @ parallel.js:31
replenish @ eachOfLimit.js:64
(anonymous) @ eachOfLimit.js:68
eachOfLimit @ eachOfLimit.js:39
(anonymous) @ doLimit.js:9
exports.default @ eachOf.js:9
_parallel @ parallel.js:30
parallelLimit @ parallel.js:88
_isInitialized @ index.js:137
waterfall @ index.js:86
nextTask @ waterfall.js:16
next @ waterfall.js:23
(anonymous) @ onlyOnce.js:12
(anonymous) @ index.js:203
(anonymous) @ levelup.js:100
g @ events.js:165
EventEmitter.emit @ events.js:78
(anonymous) @ levelup.js:123
(anonymous) @ abstract-leveldown.js:42
req2.onsuccess @ index.js:82
IndexedDB (async)
onsuccess @ index.js:69
req.onsuccess @ index.js:40
IndexedDB (async)
Level._open @ index.js:37
AbstractLevelDOWN.open @ abstract-leveldown.js:36
LevelUP.open @ levelup.js:115
LevelUP @ levelup.js:84
LevelUP @ levelup.js:45
LevelDatastore @ index.js:27
createBackend @ backends.js:6
IpfsRepo @ index.js:46
module.exports @ repo-browser.js:7
IPFS @ index.js:45
1002.ipfs @ app.js:21
s @ _prelude.js:1
e @ _prelude.js:1
(anonymous) @ _prelude.js:1
onlyOnce.js:9 Uncaught Error: Callback was already called.
    at onlyOnce.js:9
    at db.get (index.js:52)
    at dispatchError (util.js:22)
    at levelup.js:203
    at IDBTransaction.tx.onabort (index.js:104)

@daviddias
Copy link
Member

@diandianxiyu which browser are you using?

@metal-young
Copy link
Author

Chrome 60.0.3112.101

@daviddias
Copy link
Member

This is the same issue as #964

Learn more about the actual problem here: libp2p/js-libp2p-crypto#105

@daviddias
Copy link
Member

Safari support is here now! #995 (comment)

alanshaw pushed a commit to libp2p/js-libp2p-crypto that referenced this issue Jul 4, 2019
This PR adds `crypto-browserify` to the dependencies and replaces `crypto` with `crypto-browserify` when bundled in the browser.

In files that require webcrypto we check to see if it's available. If it is not we require the Node.js implementation (which has `crypto` replaced with `crypto-browserify`) and if it is available then we use the webcrypto version (so we get fast crypto).

Shipping `crypto-browserify` adds to the bundle size:

Current gzipped size: 142,824 bytes
New gzipped size: 214,499 bytes

Difference: **+71,675 bytes**

It's not an insignificant addition so we need to decide whether this is worth it.

If not accepted, we need to add checks when libp2p-crypto methods are called and callback with an appropriate error message. JS IPFS will continue to have issues opened with confusion around this otherwise! See ipfs/js-ipfs#963 ipfs/js-ipfs#964 ipfs/js-ipfs#2153

resolves #105

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
env:Safari status/ready Ready to be worked
Projects
None yet
Development

No branches or pull requests

2 participants