webflow / js-webflow-api

Node.js SDK for the Webflow Data API
https://www.npmjs.com/package/webflow-api
296 stars 95 forks source link

Cannot access API via localhost [Uncaught TypeError] #74

Closed Maybach91 closed 1 year ago

Maybach91 commented 1 year ago

Using the basic instructions to access the API like stated in the readme, i cannot make it work using it in my local environment.

I have a API Token and try to access the API via the following:

import Webflow from 'webflow-api';

// initialize the client with the access token
const webflow = new Webflow({ token: process.env.WEBFLOW_ACCESS_TOKEN });

But this shows me the following console error: Uncaught TypeError: Cannot read properties of undefined (reading 'prototype') for this line: RedirectableRequest.prototype = Object.create(Writable.prototype);

image

Is the reason because i’m trying to access it via localhost or is there something wrong with the package/my environment? Using node@v18.3.0, yarn@3.2.1 webflow-api@^1.2.0 and vite@^3.2.3

johnagan commented 1 year ago

hmm.. This error alone doesn't seem like enough information to diagnose 🤔 There shouldn't be any reason localhost is a factor. Maybe try using axios directly and see if you're getting the same error.

johnagan commented 1 year ago

I see you mention node 18, but your error appears to be a browser error. Are you attempting to load this client-side (in browser)?

Maybach91 commented 1 year ago

I see you mention node 18, but your error appears to be a browser error. Are you attempting to load this client-side (in browser)?

@johnagan yes, I’m trying to access it via client-side, I thought it’s possible with this library. But i know the API only works server side, right?

johnagan commented 1 year ago

Correct - It's a node.js library and not tested in the browser. Though, I'm not sure why it wouldn't work in the browser also. Which bundler are you using?

Also curious how you are handling access tokens in the client 🤔 Seems risky.

Maybach91 commented 1 year ago

For production i will use something like vercel for deployment and use env vars for the tokens, that should work, i think.

I’m using vite@3.2.3 as a bundler.

johnagan commented 1 year ago

You're exposing your access token in the client that way 😦

If I understand what your build is, the env variables will just populate into your compiled client code

johnagan commented 1 year ago

Closing out since I don't believe there is a change needed. Let us know if you're still having trouble!