axios-module icon indicating copy to clipboard operation
axios-module copied to clipboard

ESLint: NuxtAxiosInstance not found in '@nuxtjs/axios'(import/named)

Open slavco86 opened this issue 3 years ago • 7 comments

// package.json

"@nuxtjs/axios": "^5.13.6",
"nuxt": "^2.15.7",
import { Context } from '@nuxt/types'
import { NuxtAxiosInstance } from '@nuxtjs/axios'

const someFunc = (context: Context) => {
  const { $axios }: { $axios: NuxtAxiosInstance } = context;
  $axios.get("something")
}

ES Lint throws following errro:

error NuxtAxiosInstance not found in '@nuxtjs/axios' import/named

I looked inside axios/types/index.d.ts and there are simply no exports at all. Only module declarations. So, this makes it impossible to use NuxtAxios types anywhere in your app?

slavco86 avatar Nov 12 '21 11:11 slavco86

same here! it's happen after I use nuxtjs 3 bridge

eerison avatar Nov 16 '21 10:11 eerison

We are still on V2 and still have this issue

slavco86 avatar Nov 16 '21 14:11 slavco86

Hey @slavco86

it's strange, but take a look in my project maybe you can find something that can help you: https://github.com/eerison/myprofile/tree/master/client

I'm using nuxt2 in master and it's working as expected.

eerison avatar Nov 16 '21 16:11 eerison

quick fix for me by adding this line to .eslintrc, this happened when I updated @nuxtjs/eslint-config-typescript to version ^7.0.0

rules: {
    'import/named': 0,
},

gustiyoga avatar Nov 18 '21 08:11 gustiyoga

@gustiyoga This is not a fix. Your are simply disabling a rule. The fix should be to export all individual interfaces and types separately to allow this on-demand referencing, without having to carry the Context type around like a hot potato, just to get access to some types declared on it

slavco86 avatar Nov 18 '21 08:11 slavco86

same here! it's happen after I use nuxtjs 3 bridge

In my case I wasn't using '#app' after I change the import it back to work.

eerison avatar Nov 21 '21 09:11 eerison

Please see https://github.com/nuxt-community/axios-module/issues/555

Seems to work with import type instead of just import :)

silverbackdan avatar Mar 10 '22 16:03 silverbackdan