Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: editorjs_1.default is not a constructor

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

mmiszycommented, Nov 20, 2019

@machuu enabling "esModuleInterop": true in your tsconfig.json fixes the problem.

mmiszycommented, Nov 21, 2019

@machuu it’s import EditorJS from "@editorjs/editorjs" — without braces { } (default import). I tested it in your repository and it works.

Read more comments on GitHub >

github_iconTop 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 >
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 in a Vue component, but Vue gives me the error: TypeError: _gauge2.default is not a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found