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

ReferenceError: crypto is not defined #3845

Closed
hunterInt opened this issue Sep 1, 2021 · 6 comments
Closed

ReferenceError: crypto is not defined #3845

hunterInt opened this issue Sep 1, 2021 · 6 comments
Labels
need/triage Needs initial labeling and prioritization

Comments

@hunterInt
Copy link

  • Version:
    0.58.2

  • Platform:
    5.4.0-81-generic # 91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Severity:

High - The main functionality of the application does not work, API breakage, repo format breakage, etc.

Description:

When starting up an ipfs node I get this error:

error: ReferenceError: crypto is not defined
    at Hasher.encode (/home/hunter/Documents/projects/ipfsTest/node_modules/multiformats/cjs/src/hashes/sha2-browser.js:7:56)
    at Hasher.digest (/home/hunter/Documents/projects/ipfsTest/node_modules/multiformats/cjs/src/hashes/hasher.js:16:35)
    at RsaPublicKey.hash (/home/hunter/Documents/projects/ipfsTest/node_modules/libp2p-crypto/src/keys/rsa-class.js:45:36)
    at computeDigest (/home/hunter/Documents/projects/ipfsTest/node_modules/peer-id/src/index.js:242:19)
    at computePeerId (/home/hunter/Documents/projects/ipfsTest/node_modules/peer-id/src/index.js:247:24)
    at Function.exports.createFromPrivKey (/home/hunter/Documents/projects/ipfsTest/node_modules/peer-id/src/index.js:331:10)
    at async configureRepo (/home/hunter/Documents/projects/ipfsTest/node_modules/ipfs-core/src/components/storage.js:227:18)
    at async loadRepo (/home/hunter/Documents/projects/ipfsTest/node_modules/ipfs-core/src/components/storage.js:81:17)
    at async Function.start (/home/hunter/Documents/projects/ipfsTest/node_modules/ipfs-core/src/components/storage.js:59:41)
    at async Object.create (/home/hunter/Documents/projects/ipfsTest/node_modules/ipfs-core/src/components/index.js:260:21)

Steps to reproduce the error:

test.js:

const IPFS = require('ipfs');

let ipfsNode;

async function startMainConnection() {
	ipfsNode = await IPFS.create().catch(error => {
		console.error('error:', error);
	});
}

startMainConnection();

package.json:

{
  "dependencies": {
    "ipfs": "^0.58.2"
  }
}

Run node test.js and you'll get the same error.

I've also zipped this replication project and attached it:
ipfsTest.zip

Open the file and run npm i then node test.js to get the same error.

@hunterInt hunterInt added the need/triage Needs initial labeling and prioritization label Sep 1, 2021
@achingbrain
Copy link
Member

achingbrain commented Sep 2, 2021

Weird, it looks like it's pulling in the browser version of the sha2 hash.

What version of node are you running?

@hunterInt
Copy link
Author

@achingbrain v12.15.0

@achingbrain
Copy link
Member

Please upgrade to 14 or 16 - 12 isn't supported any more.

@hunterInt
Copy link
Author

@achingbrain thanks, that was my issue!

@achingbrain
Copy link
Member

Great!

@idancali
Copy link

@achingbrain looks like the same issue persists when calling from electron (v14);
no resolution as of yet

ReferenceError: crypto is not defined
    at Hasher.encode
    at Hasher.digest
    at loadMfsRoot 
    at async toMfsPath 
    at async mfsStat 
    at async 
    at async Object.start 
    at async Promise.all
    at async IPFS.start
    at async InProc.start
    at async Factory.spawn 

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

No branches or pull requests

3 participants