TypeError: editorjs_1.default is not a constructor
See original GitHub issueI am getting the same error as #752 when importing editorjs in TypeScript
TypeError: editorjs_1.default is not a constructor
Failing index.ts
import EditorJS from "@editorjs/editorjs";
class EditorClass {
private editor: any;
constructor() {
this.editor = new EditorJS();
}
}
var Editor: any = new EditorClass();
The TypeScript line this.editor = new EditorJS();
transpiles to different javascript, depending on how editorjs is imported:
1. const-require: Works as expected
const EditorJS = require("@editorjs/editorjs");
...
this.editor = new EditorJS();
2. module-import Error at runtime
import EditorJS from "@editorjs/editorjs";
...
this.editor = new editorjs_1.default();
3. import-require fails to transpile
import EditorJS = require("@editorjs/editorjs");
Produces the error
src/index_import-require.ts:7:19 - error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
7 this.editor = new EditorJS();
I would like to follow best practice for TypeScript imports , version (2) or (3), but both methods cause errors. I have to bypass the tslint
rule no-var-requires
to use (1).
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
Error: *.default is not a constructor - Stack Overflow
I get the following error, when testing some javascript code, transpiled from a typescript file. Here is the error: Error: _mapAction2.default ...
Read more >TypeError: web3_1.default is not a constructor
I'm trying to convert a DApp that uses web3.js from JavaScript to TypeScript, but I have encountered a bunch of runtime errors. I'm...
Read more >Hi, to fix this `o.default is not a constructor`, you need to adjust ...
to:. “Hi, to fix this `o.default is not a constructor`, you need to adjust your import statement, from:” is published by Éverton Roberto...
Read more >colyseus_js__WEBPACK_IMPO...
BattleScreen.js:16 Uncaught TypeError: colyseus_js__WEBPACK_IMPORTED_MODULE_1___default.a is not a constructor. any thoughts? Reply Quote.
Read more >TypeError: _gauge2.default is not a constructor - Laracasts
I'm trying to wrap this gauge http://bernii.github.io/gauge.js/ in a Vue component, but Vue gives me the error: TypeError: _gauge2.default is not a ......
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 FreeTop 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
Top GitHub Comments
@machuu enabling
"esModuleInterop": true
in yourtsconfig.json
fixes the problem.@machuu it’s
import EditorJS from "@editorjs/editorjs"
— without braces{
}
(default import). I tested it in your repository and it works.