Comments (6)
Using node-fetch did not work due to type errors when setting the global variable (didn't want to deal with that headache), so I opted to use cross-fetch instead, which is a better library with type defs.
Here's the code for anyone else who stumbles upon this issue:
import 'cross-fetch/polyfill';
import RemoteStorage from 'remotestoragejs';
const remoteStorage = new RemoteStorage({ logging: true });
remoteStorage.access.claim('*', 'rw');
// Replace with your token/username
remoteStorage.connect('[email protected]', 'token');
from remotestorage.js.
It seems you're trying this from node.js or a similar non-browser environment? If so, you may need a polyfill library for either XMLHttpRequest
or Fetch
.
from remotestorage.js.
How would this be implemented in typescript? The XMLHttpRequest library doesn't have any type defs on npm, so I get a bunch of errors
Therefore, I can't do global.XMLHttpRequest = xmlHttpRequest
https://www.npmjs.com/package/xmlhttprequest
Here's my full typescript code
import RemoteStorage from 'remotestoragejs';
const remoteStorage = new RemoteStorage();
remoteStorage.access.claim('*', 'rw');
remoteStorage.connect('[email protected]', 'token');
from remotestorage.js.
Update: After some research, I was able to use isomorphic-fetch for the polyfill. Is there a simpler way to accomplish this, or did I do it right?
import 'isomorphic-fetch';
import RemoteStorage from 'remotestoragejs';
const remoteStorage = new RemoteStorage({ logging: true });
remoteStorage.access.claim('*', 'rw');
remoteStorage.connect('[email protected]', 'token');
from remotestorage.js.
Good question! We only moved to typescript with 2.0.0, which is why it's still officially a beta version and native TS usage might not be 100% there yet.
Could you try https://www.npmjs.com/package/node-fetch instead?
rs.js supports both fetch and the older xmlhttprequest. But the node-fetch library comes with TS definitions bundled by default.
from remotestorage.js.
Great! I created an issue to document this properly.
from remotestorage.js.
Related Issues (20)
- Tests must be migrated away from Jaribu, which is no longer maintained HOT 2
- ReadTheDocs builds broken (again)
- hypercore, solid-project, webdav, ipfs or remote-storage? HOT 2
- getNodes does not clone object in inmemorystorage
- Is this project active? HOT 2
- Error "No storage information found for this user address." when accessing my HTTP RS server from HTTPS app HOT 2
- Error "Cannot read properties of null" when trying to login in the widget HOT 2
- Export assignment cannot be used when targeting ECMAScript modules. in 2.0.0 beta. HOT 2
- Fire local change event without page reload HOT 1
- Migrating to 2.0.0-beta.6 issues HOT 6
- Document sync events HOT 1
- npm install fails with ERESOLVE dependency conflict HOT 1
- Tests fail under NodeJS v18
- http://remotestorage.io/spec/folder-description is a dead link HOT 1
- Code overview still points to .js files instead of .ts
- Typo 'seperate' in a few places
- Jaribu test failing in CI for node 16 HOT 1
- SOLID back-end
- Doc / Type mismatch: getFile returns contentType instead of mimeType
- Correct docs about permissions for Dropbox backend (and why not Google Drive?) HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remotestorage.js.