question-mark
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.

Object is not a constructor on Typescript import * from "realm"

See original GitHub issue

Version:

  • react-native: 0.47.1
  • realm: 1.10.3

When use:

import * as Realm from "realm"

new Realm({
	schema: [{ name: 'Dog', properties: { name: 'string' } }]
})

// or
Realm.open({
	schema: [{ name: 'Dog', properties: { name: 'string' } }]
})
.then((realm) => {...})

Will show error in red screen:

Object is not a constructor (evaluating 'new Realm({
    schema: [{ name: 'Dog', properties: { name: 'string' } }]
})')

// or
Object is not a constructor (evaluating 'new _this(config)')

Change import to this type is no problem:

import Realm from "realm"

But lose type intelligence and get ts error:

Module ''realm'' has no default export.

Similar problems in stackoverflow Cannot open Realm using typescript 2.4.1 + react native 0.46.1 because Realm is not a constructor

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
BANG88commented, Sep 4, 2017

@CacaoRick could you please add a config in tsconfig.json

"allowSyntheticDefaultImports": true
1reaction
knethcommented, Sep 12, 2017

@CacaoRick Not sure how to interpret you. Does it work for you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot open Realm using typescript 2.4.1 + react native 0.46 ...
using typescript 2.4.1 and react native 0.46.1. Error I am receiving depending on how I import: TypeError: Realm is not a constructor.
Read more >
Object is not a constructor on Typescript import * from "realm"
Version: react-native: 0.47.1; realm: 1.10.3. When use: import * as Realm from "realm" new Realm({ schema: [{ name: 'Dog', properties: { name: 'string'...
Read more >
Getting Type Error Is Not A Constructor In Realm With React ...
This JavaScript exception is not a constructor that occurs if code tries to use an object or a Cause of Error: Somewhere the...
Read more >
Class extends value # is not a constructor or null in Svelte App ...
import * as Realm from 'realm-web' I have the following error : Uncaught TypeError: Class extends value # is not a constructor or...
Read more >
TypeError: "X" is not a constructor in JavaScript | bobbyhadz
TypeError : "X" is not a constructor in JavaScript # · Note that arrow functions cannot be used as constructors. · Always make...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found