nodejs-sdk icon indicating copy to clipboard operation
nodejs-sdk copied to clipboard

navigator is not defined

Open ggomaeng opened this issue 1 year ago • 4 comments

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 avatar Mar 27 '24 05:03 ggomaeng

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',
    },
  }),
});

ggomaeng avatar Mar 27 '24 05:03 ggomaeng

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

Shreyaschorge avatar Mar 27 '24 07:03 Shreyaschorge

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

v18.18.2

ggomaeng avatar Mar 27 '24 08:03 ggomaeng

@ggomaeng Sorry for getting back this late.

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

Shreyaschorge avatar May 03 '24 06:05 Shreyaschorge

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

Shreyaschorge avatar Jul 12 '24 08:07 Shreyaschorge