Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inferred types cannot be named without a reference to 'plaid/node_modules/axios' #508

Closed
m-p-d opened this issue Mar 4, 2022 · 11 comments
Closed

Comments

@m-p-d
Copy link

m-p-d commented Mar 4, 2022

Getting many "The inferred type of [x] cannot be named without a reference to 'plaid/node_modules/axios'. This is likely not portable. A type annotation is necessary." errors when building node project after upgrading to version 9.12.0. Downgrading to version 9.10.1 does not give these errors.

node_modules/plaid/api.ts:25327:12 - error TS2742: The inferred type of 'accountsBalanceGet' cannot be named without a reference to 'plaid/node_modules/axios'. This is likely not portable. A type annotation is necessary.

25327     public accountsBalanceGet(accountsBalanceGetRequest: AccountsBalanceGetRequest, options?: any) {
                 ~~~~~~~~~~~~~~~~~~
node_modules/plaid/api.ts:25339:12 - error TS2742: The inferred type of 'accountsGet' cannot be named without a reference to 'plaid/node_modules/axios'. This is likely not portable. A type annotation is necessary.

25339     public accountsGet(accountsGetRequest: AccountsGetRequest, options?: any) {
                 ~~~~~~~~~~~
node_modules/plaid/api.ts:25351:12 - error TS2742: The inferred type of 'applicationGet' cannot be named without a reference to 'plaid/node_modules/axios'. This is likely not portable. A type annotation is necessary.

25351     public applicationGet(applicationGetRequest: ApplicationGetRequest, options?: any) {

Using tsconfig.json options:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
  },
  "exclude": ["node_modules"]
}
@phoenixy1
Copy link
Contributor

phoenixy1 commented Mar 9, 2022

@m-p-d I'm not an expert on this, but some googling suggests that this might happening if your project uses a different version of axios than is used by plaid-node: microsoft/TypeScript#29808, especially if you are using TypeScript on Windows.

Can you try matching the version of axios you're using to the one used by the latest plaid-node and seeing if that fixes it? There are also a couple of other suggestions in the linked GitHub issue that resolved this for other folks that might be worth trying.

@phoenixy1
Copy link
Contributor

closing this as I haven't heard anything back -- please feel free to reply if you still need help after trying the above suggestions

@Ugikie
Copy link

Ugikie commented Nov 9, 2022

Did you ever resolve this issue? I am currently getting this error and I am using the latest version of axios (1.1.3) and it seems that plaid is using 0.21.4, which is over a year old. Is there a solution for this rather than downgrading axios? I couldn't get any of the proposed solutions to work in the linked issue.

I am using the newest axios version in order to utilize the current error handling and classes that they have implemented. Hoping I don't have to downgrade it.

@phoenixy1 phoenixy1 reopened this Nov 9, 2022
@phoenixy1
Copy link
Contributor

phoenixy1 commented Nov 18, 2022

@Ugikie can you try sending the axios you'd like to use as an argument to the plaid api constructor and let us know if that works for you?

const plaidClient = new plaid.PlaidApi(configuration, null, axios);

Based on the code at https://github.com/plaid/plaid-node/blob/master/dist/base.js we think that should work.

@Ugikie
Copy link

Ugikie commented Nov 18, 2022

@phoenixy1 Thanks so much for the response! That actually seems like exactly what I need, but unfortunately that doesn't seem to do the trick.

Here is the test code for that solution:

import axios from 'axios' // version 1.1.3
import { Configuration, PlaidApi, PlaidEnvironments } from 'plaid' // version 12.0.0

const configuration = new Configuration({
  basePath: PlaidEnvironments.sandbox,
  baseOptions: {
    headers: {
      'PLAID-CLIENT-ID': process.env.PLAID_CLIENT_ID,
      'PLAID-SECRET': process.env.PLAID_SECRET,
    },
  },
})
export const plaidClient = new PlaidApi(configuration, null, axios)

And I am getting this error:
image

If I try to create some dummy axiosInstance like this:

const axiosInstance = axios.create({
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  headers: { 'X-Custom-Header': 'foobar' },
})

and assign it via

const plaidClient = new PlaidApi(configuration, null, axiosInstance)

I get a similar error:
image

Not sure if I am still doing something wrong, but I feel like we are close!

@phoenixy1
Copy link
Contributor

:-( Dang. This is well beyond my node client library knowledge at this point -- I've assigned it to @otherchen to take a look.

@phoenixy1
Copy link
Contributor

@Ugikie ok, @otherchen gave me the following advice, does this help?
"they should be able to call create() to create an AxiosInstance.

Link to the type:
https://github.com/axios/axios/blob/786b113a40011faaee95da0b02eaa7de06944d7a/index.d.ts#L487

@phoenixy1
Copy link
Contributor

@Ugikie did you get a chance to try out the suggested solution above?

@Ugikie
Copy link

Ugikie commented Jan 17, 2023

Hey @phoenixy1 I'm so sorry I must have missed the notifications for this issue and forgot to check back on it... unfortunately, no, I was unable to solve the issue with the provided solution. I actually tried doing that initially and received the error I linked above. Just tried again today and still getting the same thing.

When doing this:

import axios from 'axios' // version 1.2.3
import { Configuration, PlaidApi, PlaidEnvironments } from 'plaid' // version 12.2.0

const axiosInstance = axios.create({
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  headers: { 'X-Custom-Header': 'foobar' },
})

const plaidClient = new PlaidApi(configuration, null, axiosInstance)

I am still getting this error:
image

Axios version 1.2.3
Plaid version 12.2.0

@Ugikie
Copy link

Ugikie commented May 17, 2023

I think I finally found a solution to this. I am now able to install a newer version of axios in the same project that I am using plaid without getting the errors about inferred types...

The issue was because I had functions that were basically proxies to the plaid client, and I was not specifying the return type of those functions, and so what would happen with the latest version of axios is that TS would try to infer the type by using AxiosResponse from node_modules/axios, which does not align with the type of AxiosResponse from plaid/node_modules/axios...

So to fix this, what I did was two things:

  1. Manually specify the return type of my function as something like: Promise<AxiosResponse<...>>
  2. Dont import the AxiosReponse type from 'axios', instead, import it from 'plaid/node_modules/axios'. For example:
// import { AxiosResponse } from 'axios' // Don't use this
import { AxiosResponse } from 'plaid/node_modules/axios' // Use this instead


// And then you can do:
export async function plaidProxyFunc(): Promise<AxiosResponse<...>> {
  return plaidClient.someFunc(...) // This also has the return type of Promise<AxiosResponse<...>>
}

@cgfarmer4
Copy link
Contributor

We have updated axios to latest in our most recent release which should resolve this without needing to import that specific version. Sounds like you had a version mismatch elsewhere before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants