vue-router: Compile error at typescript: types/router.d.ts and types/vue.d.ts

I expect “node_modules/vue-router/types/router.d.ts” do reference to “d.ts” of vue package, but tsc says this do reference to “node_modules/vue-router/types/vue.d.ts”.

reproduction

mkdir sample
cd sample

echo '{"private": true}' > package.json
npm install -D vue vue-router typescript
{
    echo 'import * as Vue from "./node_modules/vue/types/index";'
    echo 'import * as VueRouter from "./node_modules/vue-router/types/index";'
} > index.ts
$(npm bin)/tsc -t 'ES2015' index.ts

Error message

node_modules/vue-router/types/router.d.ts(2,10): error TS2305: Module '"/path/to/sample/node_modules/vue-router/types/vue"' has no exported member 'ComponentOptions'.
node_modules/vue-router/types/router.d.ts(2,28): error TS2305: Module '"/path/to/sample/node_modules/vue-router/types/vue"' has no exported member 'PluginFunction'.
node_modules/vue-router/types/router.d.ts(13,43): error TS2304: Cannot find name 'Vue'.
node_modules/vue-router/types/router.d.ts(19,8): error TS2304: Cannot find name 'Vue'.
node_modules/vue-router/types/router.d.ts(67,25): error TS2304: Cannot find name 'Vue'.
node_modules/vue-router/types/vue.d.ts(17,13): error TS2428: All declarations of 'ComponentOptions' must have identical type parameters.
node_modules/vue-router/types/vue.d.ts(17,40): error TS2304: Cannot find name 'Vue'.

https://gist.github.com/yajamon/f49ca6a7fa92a7b43e46cabb3f900aaa

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (4 by maintainers)

Most upvoted comments

@ktsn I’m still getting these errors with tsconfig.json of

{
    "compilerOptions": {
        "strictNullChecks": true,
        "declaration": true,
        "target": "es2015",
        "module": "commonjs",
        "sourceMap": true,
        "moduleResolution": "node",
        "noImplicitAny": true,
        "lib": [
            "dom",
            "es2015",
            "es2015.promise"
        ]
    },
    "include": [
        "src/**/*.ts"
    ],
    "typeAcquisition": {
        "enable": true
    }
}

Any other reason this might happen?

I have the same problem recently and fixed with a different method: by changing the way to import Vue from import vue = require('vue')to import Vue from 'vue' in both vue.d.ts and router.d.ts

The reason is that the old import is using require. And to use the require in TypeScript, there must be a export = clause in the target file, which in this case, is not.

I’m experiencing this issue as well.

Same issue but this all happened after I followed someone else’s instruction of running npm update. All of these settings are fine, but now I have the exact same set of errors.

ERROR in [at-loader] ./node_modules/vue-router/types/router.d.ts:4:35 TS2709: Cannot use namespace ‘Vue’ as a type. ERROR in [at-loader] ./node_modules/vue-router/types/router.d.ts:13:43 TS2709: Cannot use namespace ‘Vue’ as a type. ERROR in [at-loader] ./node_modules/vue-router/types/router.d.ts:19:8 TS2709: Cannot use namespace ‘Vue’ as a type. ERROR in [at-loader] ./node_modules/vue-router/types/router.d.ts:93:25 TS2709: Cannot use namespace ‘Vue’ as a type. ERROR in [at-loader] ./node_modules/vue-router/types/vue.d.ts:17:13 TS2428: All declarations of ‘ComponentOptions’ must have identical type parameters. ERROR in [at-loader] ./node_modules/vue-router/types/vue.d.ts:17:40 TS2709: Cannot use namespace ‘Vue’ as a type. ERROR in [at-loader] ./node_modules/vue/types/options.d.ts:55:18 TS2428: All declarations of ‘ComponentOptions’ must have identical type parameters.

Updating the vue-router package to the most recent version solved the problem for me.