neynarxyz / nodejs-sdk

Typescript SDK for Neynar APIs
https://neynar.com
MIT License
50 stars 10 forks source link

navigator is not defined #83

Closed ggomaeng closed 2 months ago

ggomaeng commented 6 months ago

Seems like neynar's axios dependency doesn't work properly in node.js environment.

Error

/node_modules/axios/lib/helpers/isURLSameOrigin.js:11
    const msie = /(msie|trident)/i.test(navigator.userAgent);

ReferenceError: navigator is not defined
    at standardBrowserEnv (/srv/web/mintv2-web/node_modules/axios/lib/helpers/isURLSameOrigin.js:11:41)
    at Object.<anonymous> (/srv/web/mintv2-web/node_modules/axios/lib/helpers/isURLSameOrigin.js:60:4)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Object.y (/srv/web/mintv2-web/node_modules/tsx/dist/cjs/index.cjs:1:1151)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/srv/web/mintv2-web/node_modules/@neynar/nodejs-sdk/build/neynar-api/v1/openapi/apis/cast-api.js:20:33)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)

Steps to reproduce

Create a script that uses Neynar API Client in a node.js environment.

import { NeynarAPIClient } from '@neynar/nodejs-sdk';
const client = new NeynarAPIClient(NEYNAR_API_KEY);
const user = await client.lookupUserByUsername(username);

Nenyar version

^1.13.1

Related: https://github.com/axios/axios/issues/6122

ggomaeng commented 6 months ago

Workaround, but it should work out of the box.

import axios from 'axios';
import { NeynarAPIClient } from '@neynar/nodejs-sdk';

const client = new NeynarAPIClient(NEYNAR_API_KEY, {
  axiosInstance: axios.create({
    headers: {
      'User-Agent': 'nodejs',
    },
  }),
});
Shreyaschorge commented 6 months ago

@ggomaeng What is the version of nodejs you are using?

ggomaeng commented 6 months ago

@ggomaeng What is the version of nodejs you are using?

v18.18.2

Shreyaschorge commented 4 months ago

@ggomaeng Sorry for getting back this late.

I did try with the version that you mentioned, but it worked for me.

Shreyaschorge commented 2 months ago

@ggomaeng Closing this issue. Feel free to create a new one if needed.