LiranC
LiranC

Reputation: 2480

vsCode gives a warning on apparently valid code from vue.js docs

Using Visual Studio Code 1.13.1V and following vue.js guide for lazi-loading , when i'm writing this line of code:

import Vue from 'vue'
import Router from 'vue-router'
const Health = () => import('@/components/health')

vscode throws the following problems:

file: 'file:///c%3A/projects/vue-lazy-loading/src/router/index.js'
severity: 'Error'
message: 'Expression expected.'
at: '3,22'
source: 'js'

file: 'file:///c%3A/projects/vue-lazy-loading/src/router/index.js'
severity: 'Error'
message: 'Variable declaration expected.'
at: '3,28'
source: 'js'

visually, that's how it looks: enter image description here

is there something wrong with the code, or with VS-code? what is the correct way to write it?

Upvotes: 1

Views: 1185

Answers (1)

Frank Wilson
Frank Wilson

Reputation: 3250

This is an issue with support for dynamic imports in Javascript with Visual Studio Code, which uses Typescript to parse Javascript.

Yes, this is currently not supported. Microsoft/TypeScript#14495 tracks this issue on the TypeScript side. We use TypeScript to power both our JS and TS language features.

Dynamic imports are a new Javascript feature at Stage 3 of the TC39 process. As it is not yet finished, some tools are still working on support for it.

A fix seems to be in the works.

Typescript 2.4 should include support for dynamic imports: Microsoft/TypeScript#14495

We plan on picking up TS 2.4 for VSCode 1.14 in June and it should be available in the insiders builds soon

There is currently no way to suppress this error specifically. Normally you can add // @ts-ignore before the error line to disable error checking but this does not work for syntax errors like the dynamic imports one

Upvotes: 1

Related Questions