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.

`util.inherits is not a function` error thrown when `babel-plugin-react-intl` included in project

See original GitHub issue

After upgrading to Cypress 5, a bunch of my projects failed to run with the following error

The following error originated from your test code, not from Cypress.

  > util.inherits is not a function

Though some seemed to be just fine. I was able to boil the problem down to a specific combination of babel plugin and library. It seems that this specific babel plugin interferes with cypress’s ability to bundle the correct polyfills that the library needs to function, even though the babel plugin is not being used or referenced in the project.

To illustrate the problem, I’ve created a repository that showcases the problem

https://github.com/fracmak/cypress5-jwt

I also took some screenshots of the webpack build to try and highlight what’s going on

Working build (notice the inherits package living inside the /Library/Caches/Cypress):

Screen Shot 2020-08-21 at 5 06 02 PM

Failing build (notice the inherits package living inside the project node_modules):

Screen Shot 2020-08-21 at 5 04 28 PM

What seems to happen is when that plugin is installed, Cypress starts utilizing the various local node_module libraries instead of the bundled node_modules libraries that come with the cypress binary.

This broke in Cypress 5, reverting back to 4 works just fine

Current behavior:

Cypress fails with util.inherits is not a function

Desired behavior:

No failure

Test code to reproduce

https://github.com/fracmak/cypress5-jwt

Versions

Cypress 5, MacOS/Linux, Chrome 84

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
chrisbreidingcommented, Aug 25, 2020

I wasn’t able to reproduce this with @jennifer-shehane’s code, but was with @fracmak’s repo. I found the difference was that the repo has a tsconfig.json in the cypress directory. Removing that fixed the issue. I think it has to do with the "baseUrl": "../node_modules" part.

The reason removing babel-plugin-react-intl fixes the issue is that it brings typescript along with it as a dependency, which triggers Cypress’s typescript support and loads the tsconfig.json. Without typescript existing in node_modules, the tsconfig.json doesn’t get loaded. This is also why it changed between 4.x and 5.0. We didn’t used to load the tsconfig.json.

As for a fix, I’m not sure at this point. Setting "baseUrl": "../node_modules" seems kind of odd to me, so I’m curious about the reason for that. I’m no TypeScript expert, so I’m not sure why that causes this exact issue either.

3reactions
fracmakcommented, Aug 25, 2020

Removing the baseUrl does fix the problem for me, and things still run, so that’s probably the solution to this for me at least

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: util.inherits is not a function
I've attempted several things before finally finding a solution that resolved the error. My failed attempts included: Altering the import ...
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 compilation time but throws the next error in browser when...
Read more >
Node.js util.inherits() Method - GeeksforGeeks
Node.js util.inherits() Method · constructor <Function>: It is any <function> that the user wants to be inherited from the class.
Read more >
Notices for RQA customer-managed - IBM
of this License, Derivative Works shall not include works that remain ... 2014-2015 Eli Skeggs and Project contributorsCopyright (c) 2013-2014.
Read more >
https://reviews.freebsd.org/rP460377?diff=1
${NODE_BIN} -v .endif .include <bsd.port.post.mk> Index: ... hmac-drbg "^1.0.0" inherits "^2.0.1" minimalistic-assert "^1.0.0" minimalistic-crypto-utils ...
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