vue-axios: Can't import VueAxios in typescript

I’m trying to use vue-axios in typescript project but get errors even on import:

import VueAxios from 'vue-axios'; // has no default export.
import * as VueAxios from 'vue-axios'; // resolves to a non-module entity and cannot be imported using this construct.
import VueAxios = require('vue-axios'); // Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
import { VueAxios } from 'vue-axios'; // has no exported member 'VueAxios'.

Should consider VueAxios to be default export? Or there some other methods to import the plugin?

Versions: vue-axios: 2.1.1 typescript: 2.8.1

tsconfig.json:

{
  "compilerOptions": {
    "outDir": "./src/main/webapp/",
    "sourceMap": true,
    "noImplicitAny": false,
    "module": "es2015",
    "target": "es5",
    "strict": true,
    "jsx": "react",
    "allowJs": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "skipLibCheck": true
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

@imcvampire Still misses the part that allows calling axios on global Vue.

declare module "vue/types/vue" {

  interface Vue {
    axios: AxiosInstance;
    $http: AxiosInstance;
  }

 // this
  interface VueConstructor {
    axios: AxiosInstance;
  }
}

I’ve the same problem, using typescript 2.8.1 with webpack and ts-loader

tsconfig.json:

{
  "compilerOptions": {
    "outDir": "./built/",
    "sourceMap": true,
    "strict": true,
    "noImplicitReturns": true,
    "module": "es2015",
    "moduleResolution": "node",
    "target": "es5",
    "experimentalDecorators": true
  },
  "include": [
    "./src/**/*"
  ]
}

maybe you should change the export line for the type definition.

//index.d.ts
declare class VueAxios {
  static install: PluginFunction<AxiosInstance>;
}

export default VueAxios

issue #24 fixes the import, but then loses the typing information for Vue.axios