GithubHelp home page GithubHelp logo

Comments (6)

bdashore3 avatar bdashore3 commented on May 28, 2024 1

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.

raucao avatar raucao commented on May 28, 2024

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.

bdashore3 avatar bdashore3 commented on May 28, 2024

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.

bdashore3 avatar bdashore3 commented on May 28, 2024

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.

raucao avatar raucao commented on May 28, 2024

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.

raucao avatar raucao commented on May 28, 2024

Great! I created an issue to document this properly.

from remotestorage.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.