question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
langri-shacommented, Apr 24, 2017

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')
4reactions
markpradhancommented, Jul 23, 2020
module.exports = {
  resolve: {
    mainFields: ['browser', 'module', 'main']
  }
};

Adding this to the webpack config solved it for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: util.inherits is not a function
I recently ran into an issue when I tried to import a reference to jsonwebtoken into a new Vue 3 project configured with...
Read more >
Webpack-dev-server 2 Uncaught TypeError: util.inherits is not ...
I have a problem trying when i run webpack-dev-server not console error in ... Uncaught TypeError: util.inherits is not a function.
Read more >
util.inherits - npm
util -inherits will try use Object.setPrototypeOf , if Object.setPrototypeOf is not supported, then Object.create , or manipulate prototype.
Read more >
Node.js util.inherits() Method - GeeksforGeeks
The “util” module provides 'utility' functions that are used for ... Its (i.e, util.inherits()) usage is not much encouraged instead use of ...
Read more >
Util | Node.js v19.3.0 Documentation
If the section name appears within the value of that environment variable, then the returned function operates similar to console.error() . If not,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found