TypeError: Cannot read property 'prototype' of undefined + Jest + NodeJS

error typeerror: cannot read property of undefined
uncaught typeerror: cannot read property of null
typeerror: cannot read property of undefined angular
typeerror: cannot read property of undefined typescript
typeerror: cannot read property of undefined react
typeerror: cannot read property of undefined nodejs
error typeerror: cannot read property of undefined angular 8
typeerror: cannot read property 'value' of undefined react

I am using jest for unit testing in of nodeJS APIs. I have installed jest and added it to the script in package.json as well. But facing the issue:

FAIL api/test/math.test.js ● Test suite failed to run

TypeError: Cannot read property 'prototype' of undefined

 at module.exports (node_modules/request-promise-core/configure/request2.js:34:48)
 at Object.<anonymous> (node_modules/request-promise-native/lib/rp.js:15:1)
 at Object.<anonymous> (node_modules/jsdom/lib/api.js:6:17)

 Test Suites: 1 failed, 1 total
 Tests:       0 total
 Snapshots:   0 total
 Time:        0.091s
 Ran all test suites.
 npm ERR! code ELIFECYCLE
 npm ERR! errno 1
 npm ERR! chain-analytics@1.0.0 test: `jest`
 npm ERR! Exit status 1
 npm ERR!
 npm ERR! Failed at the sample-project@1.0.0 test script.
 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Below are my sample classes for the same :

math.js :

  const sum = (a, b) => a + b
  const mul = (a, b) => a * b
  const sub = (a, b) => a - b
  const div = (a, b) => a / b

  export default { sum, mul, sub, div };

math.test.js :

 const  {sum, mul, sub, div}  = require("./math")

 test("Adding 1 + 1 equals 2", () => {
   expect(sum(1, 1)).toBe(2)
 })
 test("Multiplying 1 * 1 equals 1", () => {
   expect(mul(1, 1)).toBe(1)
 })
 test("Subtracting 1 - 1 equals 0", () => {
   expect(sub(1, 1)).toBe(0)
 })
 test("Dividing 1 / 1 equals 1", () => {
   expect(div(1, 1)).toBe(1)
 })

Any suggestions are appreciated. Thanks!


Change your exports in math.js to be:

module.exports = { sum, mul, sub, div };

NodeJS doesn't support the ES6 import/export syntax I believe.

Uncaught TypeError: Cannot read property of undefined , Out of the six primitive types defined in JavaScript, namely boolean, string, symbol, number, Null, and undefined, no other type throws as many errors as  React: Uncaught at TypeError: Cannot read property 'filter' of null within a property Hot Network Questions Which technologies depicted in the various Star Trek series over the past few decades have been realized to-date?


Export uses import. module.exports will give you require.

Modules & Require

You should change math.js either:

module.exports = { sum, mul, sub, div };

For the code:

const {sum, mul, sub, div} = require("./math");

Import / Export

Or you should use:

import { sum, mul, sub, div } from "./math";

For the code:

export default { sum, mul, sub, div };

It's just the right combination.

​​Avoiding those dang cannot read property of undefined errors , Uncaught TypeError: Cannot read property 'foo' of undefined.​ The dreaded error we all hit at some point in JavaScript development. Could be  This will result in Uncaught TypeError: Cannot read property 'value' of null. The reason will be that the element with id input does not exist. Let me break it down in simpler steps; var input = document.getElementById("input"); input // when this fails, it returns null. input = null var inputVal = input.value; // this is the same as the following.


q.js :

function sum(a, b) {
  return a + b;
}

module.exports = sum;

Uncaught TypeError: Cannot read property 'value' of undefined , Seems like one of your values, with a property key of 'value' is undefined. Test that i1 , i2 and __i are defined before executing the if statements: Uncaught TypeError: Cannot read property of undefined. JavaScript TypeErroris thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or function. This error occurs in Chrome Browserwhen you read a property or call a method on an undefined object.


TypeError: Cannot read property 'firstName' of undefined , I keep getting “TypeError: Cannot read property 'firstName' of undefined” and I cannot figure out what is going on. Does anyone have an idea? var bob  Uncaught TypeError: Cannot read property of undefined In JavaScript. Out of the six primitive types defined in JavaScript, namely boolean, string, symbol, number, Null, and undefined, no other type throws as many errors as Undefined.


Prevent “Cannot read property '…' of undefined” errors with , Every developer who did some JavaScript has got errors like “Cannot read property '…' of undefined”. There is one simple way to prevent them,  It was throwing “TypeError: Cannot read property ‘value’ of null”. Solution We are already in process of upgrading all the old code to new Xrm.WebApi code but this was kind of showstopper as custom html web resource was not loading because of this issue.


TypeError: Cannot read property 'name' of undefined · Issue #10803 , 0.0-beta.7 (from 5.3.18), when I run storybook I see an error. hooks.js:232 Uncaught TypeError: Cannot read property  must be returning null and you are also attempting to set the display property to an invalid value. There are a couple of possible reasons for this first part to be null. You are running the script too early before the document has been loaded and thus the Noite item can't be found. There is no Noite item in your HTML.