Error `Uncaught TypeError: util.inherits is not a function`

I want to use console.log in my script, so I added node: { console: true } to my configuration. Now when I try to load the script, it reports Uncaught TypeError: util.inherits is not a function. The error is occuring in the Webpack version of assert.js at the line:

util.inherits(assert.AssertionError, Error);

I nosed around a bit, and it seems that that file is being parsed twice (if I put a log statement at the top of the file, it is written to the console twice). The first time, the util object is correct and has an inherits property that is a function. The second time, util is still an object but it has no properties.

Does anyone have an idea what might be going on here? If not, I will try to put together a simple reproducible use case.

Author: Fantashit

1 thought on “Error `Uncaught TypeError: util.inherits is not a function`

  1. This is seriously annoying :hurtrealbad:. I did this in the end, because the node-util probably won’t ever get updated again:

    npm i browser-assert
    

    Then in your config, monkeypatch node-libs-browser:

    const nodeLibsBrowser = require('node-libs-browser')
    nodeLibsBrowser.assert = require.resolve('browser-assert')
    nodeLibsBrowser.util = require.resolve('util')
    

Comments are closed.