Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This resolver adds `TypeScript` support to `eslint-plugin-import(-x)`

License

NotificationsYou must be signed in to change notification settings

import-js/eslint-import-resolver-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Actions Workflow StatusCodecovtype-coveragenpmGitHub Release

Conventional CommitsRenovate enabledJavaScript Style GuideCode Style: Prettierchangesets

This is a resolver foreslint-plugin-import(-x) plugin, not an ESLint plugin itself, it addsTypeScript support toeslint-plugin-import. (Or maybe you want to tryeslint-plugin-import-x for faster speed)

This means you can:

  • import/require files with extension.cts/.mts/.ts/.tsx/.d.cts/.d.mts/.d.ts
  • Usepaths defined intsconfig.json
  • Prefer resolving@types/* definitions over plain.js/.jsx
  • Multiple tsconfigs support, just like normal
  • imports/exports fields support inpackage.json

TOC

Notice

After version 2.0.0,.d.ts will take higher priority than normal.js/.jsx files on resolvingnode_modules packages in favor of@types/* definitions or its own definition.

If you're facing some problems with rulesimport/default orimport/named fromeslint-plugin-import, do not post any issue here, because they are working exactly asexpected on our side. Takeimport-js/eslint-plugin-import#1525 as reference or post a new issue oneslint-plugin-import instead.

Installation

eslint-plugin-import-x

# npmnpm i -D eslint-plugin-import-x eslint-import-resolver-typescript# pnpmpnpm i -D eslint-plugin-import-x eslint-import-resolver-typescript# yarnyarn add -D eslint-plugin-import-x eslint-import-resolver-typescript# bunbun add -d eslint-plugin-import-x eslint-import-resolver-typescript

eslint-plugin-import

# npmnpm i -D eslint-plugin-import eslint-import-resolver-typescript# pnpmpnpm i -D eslint-plugin-import eslint-import-resolver-typescript# yarnyarn add -D eslint-plugin-import eslint-import-resolver-typescript# bunbun add -d eslint-plugin-import eslint-import-resolver-typescript

Configuration

eslint.config.js

If you are usingeslint-plugin-import-x@>=4.5.0, you can useimport/require to referenceeslint-import-resolver-typescript directly in your ESLint flat config:

// eslint.config.js (CommonJS is also supported)import{createTypeScriptImportResolver}from'eslint-import-resolver-typescript'exportdefault[{settings:{'import-x/resolver-next':[createTypeScriptImportResolver({alwaysTryTypes:true,// Always try to resolve types under `<root>@types` directory even if it doesn't contain any source code, like `@types/unist`bun:true,// Resolve Bun modules (https://github.com/import-js/eslint-import-resolver-typescript#bun)// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json or <root>/jsconfig.json by default// Use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.jsonproject:'path/to/folder',// Multiple tsconfigs/jsconfigs (Useful for monorepos, but discouraged in favor of `references` supported)// Use a glob patternproject:'packages/*/{ts,js}config.json',// Use an arrayproject:['packages/module-a/tsconfig.json','packages/module-b/jsconfig.json',],// Use an array of glob patternsproject:['packages/*/tsconfig.json','other-packages/*/jsconfig.json',],}),],},},]

But if you are usingeslint-plugin-import or the older version ofeslint-plugin-import-x, you can't userequire/import:

// eslint.config.js (CommonJS is also supported)exportdefault[{settings:{'import/resolver':{typescript:{alwaysTryTypes:true,// Always try to resolve types under `<root>@types` directory even if it doesn't contain any source code, like `@types/unist`bun:true,// Resolve Bun modules (https://github.com/import-js/eslint-import-resolver-typescript#bun)// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json or <root>/jsconfig.json by default// Use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.jsonproject:'path/to/folder',// Multiple tsconfigs/jsconfigs (Useful for monorepos, but discouraged in favor of `references` supported)// Use a glob patternproject:'packages/*/{ts,js}config.json',// Use an arrayproject:['packages/module-a/tsconfig.json','packages/module-b/jsconfig.json',],// Use an array of glob patternsproject:['packages/*/tsconfig.json','other-packages/*/jsconfig.json',],},},},},]

.eslintrc

Add the following to your.eslintrc config:

{"plugins": ["import"],"rules": {// Turn on errors for missing imports"import/no-unresolved":"error",  },"settings": {"import/parsers": {"@typescript-eslint/parser": [".ts",".tsx"],    },"import/resolver": {"typescript": {"alwaysTryTypes":true,// Always try to resolve types under `<root>@types` directory even if it doesn't contain any source code, like `@types/unist`"bun":true,// Resolve Bun modules (https://github.com/import-js/eslint-import-resolver-typescript#bun)// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json or <root>/jsconfig.json by default// Use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json"project":"path/to/folder",// Multiple tsconfigs (Useful for monorepos, but discouraged in favor of `references` supported)// Use a glob pattern"project":"packages/*/{ts,js}config.json",// Use an array"project": ["packages/module-a/tsconfig.json","packages/module-b/jsconfig.json",        ],// Use an array of glob patterns"project": ["packages/*/tsconfig.json","other-packages/*/jsconfig.json",        ],      },    },  },}

Other environments

Bun

Bun provides built-in modules such asbun:test, which are not resolved by default.

Enable Bun built-in module resolution by choosing 1 out of these 3 options:

Options fromunrs-resolver

conditionNames

Default:

["types","import",// APF: https://angular.io/guide/angular-package-format"esm2020","es2020","es2015","require","node","node-addons","browser","default",]

extensions

Default:

[// `.mts`, `.cts`, `.d.mts`, `.d.cts`, `.mjs`, `.cjs` are not included because `.cjs` and `.mjs` must be used explicitly".ts",".tsx",".d.ts",".js",".jsx",".json",".node",]

extensionAlias

Default:

{".js": [".ts",// `.tsx` can also be compiled as `.js`".tsx",".d.ts",".js",  ],".ts": [".ts",".d.ts",".js"],".jsx": [".tsx",".d.ts",".jsx"],".tsx": [".tsx",".d.ts",".jsx",// `.tsx` can also be compiled as `.js`".js",  ],".cjs": [".cts",".d.cts",".cjs"],".cts": [".cts",".d.cts",".cjs"],".mjs": [".mts",".d.mts",".mjs"],".mts": [".mts",".d.mts",".mjs"],}

mainFields

Default:

["types","typings",// APF: https://angular.io/guide/angular-package-format"fesm2020","fesm2015","esm2020","es2020","module","jsnext:main","main",]

Other options

You can pass through other options ofunrs-resolver directly.

Default options

You can reusedefaultConditionNames,defaultExtensions,defaultExtensionAlias, anddefaultMainFields by directly usingrequire/import.

Contributing

  • Make sure your change is covered by a test import.
  • Make sure thatyarn test passes without a failure.
  • Make sure thatyarn lint passes without conflicts.
  • Make sure your code changes match ourtype-coverage settings:yarn type-coverage.

We haveGitHub Actions, which will run the above commands on your PRs.

If either fails, we won't be able to merge your PR until it's fixed.

Sponsors and Backers

Sponsors and Backers

Sponsors

1stGRxTSUnTS
1stG Open Collective sponsorsRxTS Open Collective sponsorsUnTS Open Collective sponsors

Backers

1stGRxTSUnTS
1stG Open Collective backersRxTS Open Collective backersUnTS Open Collective backers

Changelog

Detailed changes for each release are documented inCHANGELOG.md.

License

ISC

Star History

Star History Chart

About

This resolver adds `TypeScript` support to `eslint-plugin-import(-x)`

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors47


[8]ページ先頭

©2009-2025 Movatter.jp