Install ESLint and the required plugins:
# If using npm
npm install eslint eslint-plugin-import --save-dev
# If using yarn
yarn add eslint eslint-plugin-import --dev
Configure ESLint: Create or modify an ESLint configuration file (e.g., .eslintrc.js or .eslintrc.json) in the root of your project. Add the following configuration to enable the "import/no-unresolved" rule:
{
"plugins": ["import"],
"rules": {
"import/no-unresolved": "error"
}
}
Configure TypeScript: If you're using TypeScript, make sure you have a TypeScript configuration file (e.g., tsconfig.json) in the root of your project. Ensure that the baseUrl and paths options are correctly configured to match your project structure. This helps TypeScript resolve module imports properly. For example:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
Run ESLint:
npx eslint --ext .ts .