Search code examples
webpackbrowser-synccryptojs

_crypto is not defined


I've been digging on this for about an hour, but can't figure out what's causing the issue. I'm using webpack, browser-sync, and react with react-redux. Here's the error from the console:

Uncaught ReferenceError: _crypto is not defined
    at eval (eval at <anonymous> (bundle.js:881), <anonymous>:5:11)
    at Object.eval (eval at <anonymous> (bundle.js:881), <anonymous>:20:3)
    at eval (eval at <anonymous> (bundle.js:881), <anonymous>:21:30)
    at Object.<anonymous> (bundle.js:881)
    at __webpack_require__ (bundle.js:20)
    at Object.eval (eval at <anonymous> (bundle.js:875), <anonymous>:3:11)
    at eval (eval at <anonymous> (bundle.js:875), <anonymous>:46:30)
    at Object.<anonymous> (bundle.js:875)
    at __webpack_require__ (bundle.js:20)
    at Object.eval (eval at <anonymous> (bundle.js:833), <anonymous>:4:14)

Solution

  • I just encountered this too. The solution for me was to upgrade the crypto-browserify dependency:

    npm install crypto-browserify@3.11.0
    

    EDIT 1: For reasons I don't quite grasp, this only fixed the problem temporarily. As soon as I restarted webpack, it stopped working again.

    EDIT 2: This happens only in one of my projects, which is rather complex, so it's hard to pin down exactly what the differences are between the two, but as a temporary fix, you can just declare the variable:

    window._crypto = null;
    

    It's not pretty, but hopefully this will be temporary.