Vetur: Couldn't resolve `'types' can only be used in a .ts file. Vetur(8010)`

Created on 3 Jul 2019  路  6Comments  路  Source: vuejs/vetur

  • [x] I have searched through existing issues
  • [x] I have read through docs
  • [x] I have read FAQ

Info

  • Platform: macOS
  • Vetur version: 0.21.1
  • VS Code version: 1.35.1

Problem



I tried to use Vetur in my project of TypeScript with Nuxt.js. Then, 'types' can only be used in a .ts file. Vetur(8010) appeared.

vetur-with-nuxt-2019-7-4-1

However, I found this message didn't appear when I tried to use Vetur in a project of TypeScript with Vue CLI.

Would you show me how deal with that message when using Vetur in TypeScript with Nuxt.js?

no-repro-case

Most helpful comment

It shouldn't be appeared if the block is lang="ts". Can you provide a self-contained repro? (pasting .vue file, providing example github repo etc.)

All 6 comments

It shouldn't be appeared if the block is lang="ts". Can you provide a self-contained repro? (pasting .vue file, providing example github repo etc.)

I found it is possible to solve this problem through removing vue-property-decorator and adding nuxt-property-decorator. So it is not problem of Vetur. I'm sorry.

My solution to this problem:
I added "allowJs": true and "checkJs": true to file tsconfig.json.

My solution was to:

  • Ensure I had lang="ts" as an attribute in my script tag (as described above)
  • Restart VS Code

In case it helps anyone else, I also ran into this issue when I had a <script lang="ts"> block and later in the same component I had an additional, leftover <script> block.

For people using @flow, using <script lang="js"> fixes the issue in a similar manner.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AnnAngela picture AnnAngela  路  3Comments

thibautguedou3 picture thibautguedou3  路  3Comments

muhajirdev picture muhajirdev  路  3Comments

OsterHuang picture OsterHuang  路  3Comments

yoyoys picture yoyoys  路  3Comments