I get Super expression must either be null or a function, not object error when I run index.js
I see another post here with similar error message. But looks like that is related to react!
export default class Base{
constructor(title){
console.log(title);
}
}
import * as Base from './base';
export default class Class1 extends Base{
constructor(title){
super(title);
}
}
import * as Class1 from './class1';
'use strict';
function check() {
var c = new Class1('from Index.js');
}
check();
{ "presets": [ "es2015", "stage-1" ] }
dependencies": {
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-syntax-export-extensions": "^6.13.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"babel-register": "^6.24.1"
}
Please help! Thanks in advance !
You're doing namespace imports (* as …
) that create namespace objects in your variables, which are not functions indeed like the error message says. You will want to import the default exports:
import Base from './base';
and
import Class1 from './class1';
When you import, you are importing the entire js file, which is an object. You need to import just the class from your js file.
To use just a class do
import {myMember} from 'my-module';
Which imports just the member called myMember
.
You are doing this
import * as myModule from 'my-module';
Which imports all of the members of your file as sub-members of the myModule
object.
See Importing in JS (examples from here)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With