Registry / testing / eslint-plugin-import-typescript

eslint-plugin-import-typescript

JSON →
library0.0.4jsnpmunverified

This ESLint plugin automates the conversion of relative import paths to absolute or path-mapped imports within TypeScript and JavaScript projects. Currently at version 0.0.4, it's an early-stage project focused on providing auto-fixing capabilities for import path management. It directly integrates with `tsconfig.json` (or `jsconfig.json`)'s `baseUrl` and `paths` configurations, addressing a common pain point where TypeScript's compiler understands these settings but does not rewrite the import paths in the compiled output. A key differentiator is its ability to auto-fix rules like `no-relative-parent-imports`, which some other plugins might only flag. It aims to streamline the migration from relative to absolute imports, particularly as project scale increases. There is no explicit release cadence, typical for community-driven ESLint plugins.

npm install eslint-plugin-import-typescript
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-IMPO
E
eslint-plugin-import-typescript
testingjavascriptv0.0.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ESLint Plugin Configuration
plugins: ['eslint-plugin-import-typescript']
plugins: ['import-typescript']
When enabling the plugin in your `.eslintrc.js` or `.eslintrc.json`, ensure you use the full npm package name, including the `eslint-plugin-` prefix, in the `plugins` array.
Rule: no-relative-parent-imports
'import-typescript/no-relative-parent-imports': ['error']
'no-relative-parent-imports': ['error']
ESLint rules provided by plugins must be prefixed with the plugin's short name (e.g., `import-typescript/`) followed by the rule name.
Rule Options: onlyAbsoluteImport
'import-typescript/no-relative-parent-imports': ['error', { onlyAbsoluteImport: true }]
'import-typescript/no-relative-parent-imports': ['error', { onlyAbsoluteImport = true }]
Rule options are passed as a plain JavaScript object in the second element of the rule's array configuration. Ensure correct JSON/JavaScript object literal syntax (key-value pairs separated by colons).

This configuration demonstrates the basic setup for `eslint-plugin-import-typescript` in a TypeScript project, enabling its `no-relative-parent-imports` rule for automatic fixing. It also includes the necessary `parserOptions` for TypeScript and `import/resolver` settings for `eslint-plugin-import` to correctly interpret `baseUrl` and `paths` from `tsconfig.json`.

{ // .eslintrc.js or .eslintrc.json "root": true, "parser": "@typescript-eslint/parser", "parserOptions": { // Point to your tsconfig.json for absolute path resolution "project": "./tsconfig.json", // If tsconfig.json is not in the root, specify its root directory // "tsconfigRootDir": "__dirname", "ecmaVersion": "latest", "sourceType": "module" }, "plugins": [ "eslint-plugin-import-typescript", // 'eslint-plugin-import' is generally recommended for any project using imports, // and is crucial for the resolver to work. "import" ], "rules": { // Enable the primary rule from this plugin to auto-fix relative parent imports. 'import-typescript/no-relative-parent-imports': [ 'error', // Optional: enforce only absolute imports, ignoring 'paths' in tsconfig // { "onlyAbsoluteImport": true } ], // Recommended: Enforce no unresolved imports, requires 'eslint-import-resolver-typescript'. 'import/no-unresolved': 'error', // Optional: Turn off default relative package rules if they conflict during migration // 'import/no-relative-packages': 'off' }, "settings": { // Crucial for ESLint and eslint-plugin-import to understand TypeScript's baseUrl and paths "import/resolver": { "typescript": { // This ensures the resolver uses your project's tsconfig for path resolution "project": "./tsconfig.json" }, // Node resolver is useful for resolving standard Node.js modules or packages "node": { "extensions": [".js", ".jsx", ".ts", ".tsx"] } } } }
Debug
Known issues
gotchaTypeScript's `baseUrl` and `paths` configurations are primarily for compile-time module resolution and do not automatically rewrite import paths in the transpiled JavaScript output. For Node.js runtime, you will need tools like `tsconfig-paths` or `tsc-alias` to make absolute imports work correctly at runtime or build time.
fix
Integrate `tsconfig-paths` for runtime resolution (e.g., `node -r tsconfig-paths/register your-app.js`) or `tsc-alias` into your build process (e.g., `tsc && tsc-alias`). For Jest, configure `moduleNameMapper` and potentially `tsconfig-paths` for `globalSetup` scripts.
affects: >=0.0.1
gotchaTo ensure ESLint correctly understands `paths` defined in your `tsconfig.json` (or `jsconfig.json`) and avoids 'Unable to resolve path' errors, you must install and configure `eslint-import-resolver-typescript` alongside `eslint-plugin-import`.
fix
Install `npm install --save-dev eslint-plugin-import eslint-import-resolver-typescript` and add the `import/resolver` setting to your `.eslintrc.js` file: `settings: { 'import/resolver': { typescript: { project: './tsconfig.json' } } }`.
affects: >=0.0.1
breakingThis plugin requires `baseUrl` to be explicitly defined in your `tsconfig.json` or `jsconfig.json` for its rules to function. If `baseUrl` is missing, the plugin will not be able to resolve absolute import paths.
fix
Add or verify the `baseUrl` property in your `tsconfig.json` (e.g., `compilerOptions: { 'baseUrl': '.' }`).
affects: >=0.0.1
gotchaAs an early-stage plugin (version 0.0.4), it may have edge cases, bugs, or incomplete feature support. Users should test thoroughly and report issues. Behavior might change rapidly in pre-1.0 versions without strict adherence to semantic versioning for breaking changes.
fix
Monitor the GitHub repository for updates and breaking changes. Contribute bug reports or feature requests if issues are encountered. Consider this plugin for new projects or non-critical paths until it reaches a more stable major version.
affects: 0.x
Errors
Common errors & fixes
ESLint: Unable to resolve path to module 'src/utils/helpers'.
ESLint, specifically `eslint-plugin-import`, cannot understand TypeScript `paths` or `baseUrl` aliases without a dedicated resolver, leading to module not found errors.
fix
Install `eslint-import-resolver-typescript` and configure it in your `.eslintrc.js` `settings['import/resolver']` to point to your `tsconfig.json`.
Error: Cannot find module 'src/components/Button' (at runtime or during build).
The TypeScript compiler understands `baseUrl` and `paths` for type checking and compilation, but Node.js runtime (or the compiled JavaScript output) does not automatically rewrite these paths by default, leading to module not found errors.
fix
For runtime execution, use `tsconfig-paths` (e.g., `node -r tsconfig-paths/register your-app.js`). For build output, integrate `tsc-alias` into your post-compilation step (e.g., `tsc && tsc-alias`).
Error: You have used a rule which requires a parser.
ESLint is not configured with a TypeScript-compatible parser (like `@typescript-eslint/parser`) or is not correctly linked to your project's `tsconfig.json`.
fix
Install `@typescript-eslint/parser` and configure it in your `.eslintrc.js` `parser` option and `parserOptions.project` (e.g., `parser: '@typescript-eslint/parser', parserOptions: { project: './tsconfig.json' }`).
Upgrade
Version history
0.0.4latest on npm
Audit
Dependencies
eslintrequiredRequired peer dependency for any ESLint plugin to function within an ESLint environment.
Agent activity
4 hits · last 30 days
node
4
Resources
eslint-plugin-import-typescript — npm install eslint-plugin-import-typescript · libregistry