janhommes / o.js

o.js - client side oData lib.
https://janhommes.github.io/o.js/example/
MIT License
238 stars 57 forks source link

Cannot read property 'disablePolyfill' of undefined #85

Closed iammatis closed 5 years ago

iammatis commented 5 years ago

I'm trying to access my odata endpoint like so:

const odata = require("odata");

test().catch(err => console.error(err));

async function test() {
  await odata
    .o("https://.../odata/v4/")
    .get("Location")
    .then(data => console.log(data));
}

But i'm getting the following error:

TypeError: Cannot read property 'disablePolyfill' of undefined
    at Object.o (/Users/matis/Documents/apps/odata/node_modules/odata/dist/cjs/o.js:537:38)
    at test (/Users/matis/Documents/apps/odata/index.js:7:6)
    at Object.<anonymous> (/Users/matis/Documents/apps/odata/index.js:3:1)
    at Module._compile (internal/modules/cjs/loader.js:722:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:775:12)
    at startup (internal/bootstrap/node.js:300:19)

Also, where did the rest of the documentation go ? Previous version, had much more of it. I can't see anything for post() or save() as it was before.

janhommes commented 5 years ago

Sorry, the example on the documentation page is wrong. Will update that.

Here you can see how to use it in node:

const odata = require('odata');

const oHandler = odata.o('https://services.odata.org/V4/%28S%28wptr35qf3bz4kb5oatn432ul%29%29/TripPinServiceRW/', {
  headers: {
    'If-Match': '*'
  }
});

oHandler.get('People').query().then((data) => {
  console.log(data);
});

Many examples are in the src/o.spec.ts. But you are right, we might need some better docs.

janhommes commented 5 years ago

Documentation was updated