Uncaught TypeError: Class constructor [extended class] cannot be invoked without 'new'
See original GitHub issueChoose one: is this a 🐛 bug report or 🙋 feature request?
🎛 Configuration (.babelrc, package.json, cli command)
// .babelrc
{
"presets" : ["es2015-ie"]
}
//.postcssrc
{
"modules": true,
"plugins": {
"autoprefixer": {
"grid": true
}
}
}
//package.json
{
"name": "",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "./node_modules/.bin/parcel --no-cache ./src/index.html --out-dir ./dist",
"build": "./node_modules/.bin/parcel build --no-minify ./src/index.html --out-dir ./dist"
},
"author": "",
"license": "",
"dependencies": {
"acorn": "^5.4.1",
"babel-preset-es2015-ie": "^6.7.0",
"mobile-detect": "^1.4.1",
"node-sass": "^4.7.2",
"parcel-bundler": "^1.6.1",
"postcss-modules": "^1.1.0",
"webpack": "^3.1.0",
"wrench-set": "^1.0.6"
}
}
🤔 Expected Behavior
It should just create the class and do the magic of Element. (wrench-set was created by me, and tested in another project, which works perfectly, using parcel 1.5.1)
😯 Current Behavior
it shoots error with class constructor cannot be invoked without new for the super()
Uncaught TypeError: Class constructor Element cannot be invoked without ‘new’ at new Viewport (viewport.js:5) at Object.require.4…/index.scss (index.js:4) at newRequire (3127ebea6fd59e02267b4119b100f294.js:42) at require.14 (3127ebea6fd59e02267b4119b100f294.js:69)
💁 Possible Solution
the hacky way 😄 revert to 1.5.1 in order to be able to successfully compile the code
🔦 Context
💻 Code Sample
// main.js
import style from './index.scss'
import Viewport from './viewport.js'
const VIEWPORT = new Viewport({
renderTo: document.body
})
// viewport.js
import {Element} from 'wrench-set'
import style from './viewport.scss'
export default class Viewport extends Element {
constructor (config) {
super({
renderTo: config.renderTo,
innerHTML: 'hi',
className: `${style.viewport}`
})
}
}
🌍 Your Environment
| Software | Version(s) |
|---|---|
| Parcel | 1.6.1 |
| Node | 8.9.3 |
| npm/Yarn | 5.5.1 |
| Operating System | Linux Mint 18 |
Issue Analytics
- State:
- Created 6 years ago
- Reactions:26
- Comments:25 (6 by maintainers)
Top Results From Across the Web
Javascript ES6 TypeError: Class constructor Client cannot be ...
The problem is that the class extends native ES6 class and is transpiled to ES5 with Babel. Transpiled classes cannot extend native classes, ......
Read more >Class constructor cannot be invoked without 'new' in JS
Creates a new object that inherits the prototype of the class. · Calls the constructor function with the provided parameters and binds the...
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 >Reactjs " Class constructor upload cannot be invoked without ...
Uncaught TypeError : Class constructor Upload cannot be invoked without 'new'. i dont know what to do with it:
Read more >Angular script compilation: TypeError: Class constructor ...
TypeError : Class constructor MyScript cannot be invoked without 'new' at requireScriptForNodes (tools.ts:71) at attachScripts (tools.ts:220) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I got a fix to get it work with Parcel. This makes it to not remove the
classsyntax. But it’ll hurt older browsers:Add this to your
package.jsonand Parcel will pick it up as babel config.I had a similar issue. I was extending a class exported from a node module. Upon inspecting the compiled code, I noticed that my class was transpiled into an ES5 class, but the code coming from the node modules was not being transpiled (it was still defined with the
classkeyword, etc).So it was essentially an ES5 class extending an ES6 class, and that seems to cause this error. I haven’t managed to fix it yet, but it seems like one reason might be that Parcel isn’t compiling the module.
Here’s the module in question.. Maybe it has something in common with
wrench-set?