Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I get warnings when importing modules that don't exist

Tags:

Im using EsLint with VsCode.

How can I have an error appear when trying to import a module that doesn't exist ?

for example

import foo from './this-path-doesnt-exist'

Should underline in red. Does this require an eslint plugin ?

like image 794
Lev Avatar asked Oct 16 '17 16:10

Lev


2 Answers

If you are using eslint as your linter, you can use eslint-plugin-import .

This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, and prevent issues with misspelling of file paths and import names

like image 70
Ori Drori Avatar answered Sep 30 '22 01:09

Ori Drori


In addition to the eslint plugin suggested, you can enable semantic checking for a JS file in VS Code by adding // @ts-check at the top of the file:

// @ts-check
import foo from './this-path-doesnt-exist'

enter image description here

This will enable a number of other checks in the file as well, including type checking, so it may not be appropriate for every code base but it can help catch many common programming mistakes.

More info about ts-check

like image 30
Matt Bierner Avatar answered Sep 30 '22 00:09

Matt Bierner