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.

TypeError: Class constructor Component cannot be invoked without 'new'

See original GitHub issue

Hi guys! So I am getting this error, been busting my head over it all day, any thought?

Help, much appreciated 😄.

src/index.js

import {h, render, Component} from 'ink'

export default class extends Component {
  render() {
    return (
      <div>a</div>
    )
  }
}

demo.js

import {h, render} from 'ink'
import Route from './src/index'

// Router
const Demo = () => {
  return (
    <Route/>
  )
}

// Ink
render(<Demo/>)

.babelrc

{
  "presets": ["es2015", "stage-2"],
  "plugins": [
    ["transform-class-properties"],
    ["transform-react-jsx", {
      "pragma": "h",
      "useBuiltIns": true
    }],
    ["transform-object-rest-spread",
    {
      "useBuiltIns": true
    }]

  ]
}

package.json

{
  "name": "ink-router",
  "version": "1.0.0",
  "description": "A router component for Ink.",
  "license": "MIT",
  "main": "dist/index.js",
  "scripts": {
    "pretest": "npm run build",
    "test": "xo",
    "start": "babel-node dist/index.js",
    "demo": "babel-node demo.js",
    "build": "babel src --out-dir=dist",
    "prepublish": "npm run build"
  },
  "engines": {
    "node": ">=6"
  },
  "files": [
    "dist"
  ],
  "keywords": [
    "ink",
    "ink-component"
  ],
  "dependencies": {
    "ink": "^0.3.0",
    "prop-types": "^15.5.10"
  },
  "devDependencies": {
    "babel-cli": "^6.24.1",
    "babel-eslint": "^7.2.3",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-node6": "^11.0.0",
    "babel-preset-stage-2": "^6.24.1",
    "eslint-config-xo-react": "^0.13.0",
    "eslint-plugin-react": "^7.2.0",
    "eslint-plugin-xo": "^1.0.0",
    "xo": "^0.18.2"
  },
  "xo": {
    "extends": "xo-react",
    "parser": "babel-eslint",
    "esnext": true,
    "space": true,
    "semicolon": false,
    "rules": {
      "new-cap": 0,
      "complexity": 0,
      "default-case": 0,
      "react/no-unused-prop-types": 1
    },
    "settings": {
      "react": {
        "pragma": "h"
      }
    }
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
mgripcommented, May 20, 2018

if anyone stumbles upon this using the env preset like I was, you can set a more specific target to prevent babel from transpiling ES6 classes

.babelrc:

{
  "presets": [["env", { "targets": { "node": "current" } }]],
  "plugins": [
    [
      "transform-react-jsx",
      {
        "pragma": "h"
      }
    ]
  ]
}
2reactions
vadimdemedescommented, Aug 13, 2017

This is happening, because Babel’s preset-es2015 transpiles ES6 classes. This is a very popular issue, I’d say - https://github.com/babel/babel/issues/4269.

Solution would be to use presets that target more modern Node.js versions, for example - https://www.npmjs.com/package/babel-preset-es2015-node5.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class constructor cannot be invoked without 'new' in JS
Class constructor cannot be invoked without 'new' in JS # · Creates a new object that inherits the prototype of the class. ·...
Read more >
Javascript ES6 TypeError: Class constructor Client cannot be ...
When I try to execute nodemon command I always see this error TypeError: Class constructor Client cannot be invoked without 'new'.
Read more >
`TypeError: Class constructor cannot be invoked without 'new ...
Bug report. Getting the following error in my project: TypeError: Class constructor cannot be invoked without 'new'.
Read more >
Reactjs " Class constructor upload cannot be invoked without ...
Im trying to activate a function with reactjs But i keep getting the same error: Uncaught TypeError: Class constructor Upload cannot be ...
Read more >
Javascript ES6 TypeError Class constructor Client cannot be ...
Javascript ES6 TypeError Class constructor Client cannot be invoked without new ... What I am trying to do is, I have created a...
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