7

I am trying to configure a project with minimal configuration. I want to use VueJS and Typescript.

I add the vue.js file and a script to my home page :

<script src="~/lib/vue/dist/vue.js"></script>
<script src="~/js/site.js" ></script>

Everything works fine.

But if I want to use Typescript, the Vue class is not found :

Symbol 'Vue' cannot be properly resolved, probably it is located in inaccessible module

Because the definitions file uses export, so Vue must be used as a module.

If I add the import, it will compile, but it will be in the output and won't work in the browser.

Is there a way to make this work without using webpack ?

4
  • Why won’t it work in the browser?
    – Kokodoko
    Apr 21, 2018 at 9:41
  • I have an error : SCRIPT1086: SCRIPT1086: Module import or export statement unexpected here
    – glacasa
    Apr 21, 2018 at 9:50
  • 1
    I don't think there's a way doing this without a bundler as vue is already pre-packed in your example and therefore most likely not compatible with typescript at that point anyway. I'd highly recommend you use the new vue-cli version 3, as this allows you to setup a typescript vue project with no configuration. Apr 21, 2018 at 13:57
  • It seems you're right. thanks
    – glacasa
    Apr 22, 2018 at 14:54

1 Answer 1

0

Typescript types for vue have to be imported by default. You can get them working without import using custom type definition file like this:

Create new file global.d.ts - name does not matter

//global.d.ts
import { VueConstructor } from 'vue'

declare global {
    const Vue: VueConstructor
}
1
  • This fails on the const Vue: VueConstructor line with Error TS2403 (TS) Subsequent variable declarations must have the same type. Variable 'Vue' must be of type 'typeof import, but here has type 'VueConstructor<Vue>'
    – stovroz
    May 20, 2019 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.