How can I get warnings when importing modules that do not exist

Im using EsLint with VsCode.

How can I get an error when trying to import a module that does not exist?

eg

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

It should be emphasized in red. Does this require an eslint plugin?

+5
source share
2 answers

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

This plugin intends to support ES2015 + (ES6 +) listing of import / export syntax and prevent problems with spelling paths and import names

+2
source

In addition to the proposed eslint plugin, you can enable semantic verification of the JS file in VS code by adding // @ts-check to the beginning of the file:

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

enter image description here

This will also allow you to perform a number of other checks in the file, including type checking, so it may not be suitable for each code base, but it can help catch many common programming errors.

Read more about ts-check

+1
source

Source: https://habr.com/ru/post/1272671/


All Articles