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.

Using ObjectClass throws error upon write in Node.js.

See original GitHub issue

The following works fine on ReactNative, but throws an error in Node.js.

  • realm-js v1.2.0
  • Node v7.0.0

Error:

realm.write(() => {
      ^
TypeError: Class constructor Car cannot be invoked without 'new'

Code:

const Realm = require('realm');

const CarSchema = {
  name: 'Car',
  properties: {
    color: 'string',
  },
};

class Car {};

Car.schema = CarSchema;

const realm = new Realm({
  path: 'foo.realm',
  schema: [Car],
});

realm.write(() => {
  realm.create('Car', {color: 'red'});
});

I have also tried making these changes, but had the same results:

  • realm.create(Car, {color: 'red'});
  • class Car extends Realm.Object {};

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
blagoevcommented, May 22, 2017

Hi, sorry for the late reply. We don’t support ES6 classes natively on node. On react that code is being transpiled before running the app so it works there. On node you will need to transpile your code before running it.

cheers

0reactions
fronckcommented, Feb 17, 2022

I’m closing this issue as we no longer support RealmJS < v6. I haven’t been able to reproduce the issue on v6 or v10.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js Error Handling Best Practices: Ship With Confidence
When JavaScript finds a throw keyword, the first thing it does is stop dead in its tracks. This event prevents any more functions...
Read more >
Pass an object with JS throw new Error in node - Stack Overflow
The constructor for an Error object expects a string, not an object (which is why your scheme doesn't work).
Read more >
Better Error Handling In NodeJS With Error Classes
This article is for JavaScript and NodeJS developers who want to improve error-handling in their applications.
Read more >
How to Throw Exceptions in Node.js - Rollbar
TypeError: this occurs when you attempt to use a variable that is not a valid type; URIError: this error occurs whenever encodeURI or...
Read more >
A Comprehensive Guide To Error Handling In Node.js
You can also throw it, which causes the Error object to become an exception. Once you throw an error, it bubbles up the...
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