ReferenceError: self is not defined

Hi all, I am running the server.js sample code for NodeJS and I get the following error:

exports.default = (self.crypto || self.msCrypto);

ReferenceError: self is not defined
    at Object.<anonymous> (/cert-blockchain/node_modules/@blockcerts/hashlink-verifier/lib/cjs/hashlink/crypto-browser.js:5:20)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/cert-blockchain/node_modules/@blockcerts/hashlink-verifier/lib/cjs/hashlink/codecs.js:35:42)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)

My NodeJS version is v16.15.0 and my cert-verifier-js version is 5.13.0.

The documentation indicates that it is possible to run cert-verifier-js from NodeJS

Can anyone help me?


The code should be available from @blockcerts/cert-verifier-js/lib.
The build tests seem to be working so I haven’t noticed any issue, but please confirm if that works, the issue seems to be coming from a sub package.

I installed the dependencies on the @blockcerts/cert-verifier-js path using the npm install --legacy-peer-deps command and I get the same error.

I don’t know if this is the right thing to do because I am new to NodeJS. Please guide me about it.

I have tracked this issue here: Node build is broken · Issue #1380 · blockchain-certificates/cert-verifier-js · GitHub

If you are using any script file and getting "Uncaught ReferenceError: x is not defined " which means ‘x’ is either a variable or a method which you are trying to use before declaring it using var keyword. This means that there is a non-existent variable referenced somewhere. This variable needs to be declared, or you need to make sure it is available in your current script or scope otherwise , it will endup throwing this ‘x’ is not defined error . This usually indicates that your library is not loaded and JavaScript does not recognize the ‘x’.

To solve this error: Load your library at the beginning of all your scripts.

There can be multiple other reasons for this issue:

  • Conflict with Other Libraries
  • Path to your library included is not correct
  • Llibrary file is corrupted
  • Working offline (when you use CDN)