Reputation: 742
I make a typescript npm package, simply like this:
class Core{
constructor(){}
//some functions
}
export = Core;
declare class Core {
constructor(){}
//some functions
}
export = Core;
{
"name": "@company/Core",
"main": "dist/Core.js",
"typings": "dist/Core" //.d.ts
//etc
}
I make this module with webpack and ts-loader.
In my project, index.ts
import Core = require('@company/Core');
let core = new Core(); //Error, Core is not a function
I have tried to change export
and import
in some form but no luck. Do I miss some knowlage?
Upvotes: 1
Views: 353
Reputation: 742
Finally, I solve my promble by myself. I add two properties in webpack configuration file, then recompile it and works well.
module.exports = {
output: {
libraryTarget: 'commonjs'
}
//etc
}
Upvotes: 1