Using ObjectClass throws error upon write in Node.js.
See original GitHub issueThe 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:
- Created 6 years ago
- Comments:12 (4 by maintainers)
Top 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 >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
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
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.