Is there a way to ensure the validity and usage of all imports during the build or linting phase in a Typescript based project?
- validity (checking for paths that lead to non-existent files)
- usage (detecting any unused imports)
We recently encountered an issue where our project passed the build and linting processes, but failed to run on our development server due to an invalid relative import path after CI/CD.
For instance, the build step was successful but it failed at runtime because the correct path should have been ../utils/date
:
import { parseDate } from '../../utils/date';
In addition, even though the following import statement was greyed out as unused in Visual Studio Code, it wasn't flagged during linting or building:
import { displayInfo } from '../../utils/display';