I created an es6 library for some of my projects.
When I import this library all static functions raise an error.
This is an example.
My Class (es6) :
class JsonSerializer {
static toJson(node) { /* some code */ }
}
export default JsonSerializer
Typescript definition file :
export class JsonSerializer {
static toJson(root: Node): any
static fromJson(config: any): Node
}
I import my class like this
import {JsonSerializer} from 'ls-serializer'
When I try to use toJson static method.
And its give me following error :
_lsSerializer.JsonSerializer.toJson is not a function
I've same error for all static method.
Did I miss something ?
EDIT
This is my library webpack config :
const path = require('path');
module.exports = {
entry : {
serializer : './src/serializer.js'
},
output : {
path : path.resolve(__dirname, 'dist'),
filename : '[name].bundle.js',
libraryTarget: 'commonjs-module'
},
resolve : {
extensions : ['.js', '.jsx'],
alias : {
'@' : path.resolve(__dirname, 'src'),
'~' : path.resolve(__dirname, 'examples')
}
},
devServer : {
contentBase : path.resolve(__dirname, 'dist'),
compress : true,
port : 9000
},
module : {
rules : [{
test : /\.(js|jsx)$/,
exclude : /node_modules/,
loader : 'babel-loader'
}, {
test : /\.(html)$/,
use : {
loader : 'html-loader',
options : {
attrs : [':data-src']
}
}
}]
},
devtool : 'source-map',
mode : 'development'
};
And this is ./src/serializer.jsfile code :
import JsonSerializer from './serializers/JsonSerializer'
export {
JsonSerializer, /* other exports*/
}
_lsSerializer? I mean, where is it coming from?toJsonstatic method?TypeError: ls_serializer__WEBPACK_IMPORTED_MODULE_3__.JsonSerializer.toJson is not a functionconst res = JsonSerializer.toJson(currentNode).