Sunday, April 5, 2020

TypeError: Class extends value undefined is not a constructor or null



Error Blog 

This blog is about the error TypeError: Class extends value undefined is not a constructor or null

Problem Statement

unable to start reactjs application

Error Details 

error Log

ERROR DETAILS 

Uncaught TypeError: Class extends value undefined is not a constructor or null
    at Module../src/task/task-list.js (task-list.js:5)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Module../src/App.js (App.css?4433:45)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Module../src/index.js (index.css?f3f6:45)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object.1 (task.js:11)
    at __webpack_require__ (bootstrap:784)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1




Error Code 

You will face this error if you have improper syntax in extends React.Component.




import React from 'react';



class TaskList extends React.Component() {
  constructor() {
    super();
    this.state = {
      name: 'React',assetName:"asset name"
    };
  }
 
  render() {
     return (
    <div  >
       Task List
    </div>
  );
  }
}


export default TaskList;



  

Solution

change the code so that the syntax is proper for extends  . .

Code Changes 

add the following import in your component.ts file .

  
        
     class TaskList extends React.Component  {
         

OUTPUT
works 



Thanks for reading . Let me know your thoughts in the comments below    .

No comments:

Post a Comment

ec2-user@ec2 Permission denied