Support for TypeScript's path mapping in Vite
Installations
npm install vite-tsconfig-paths
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
23.1.0
NPM Version
10.9.0
Score
55.9
Supply Chain
90.8
Quality
89.3
Maintenance
100
Vulnerability
98.6
License
Releases
Contributors
Languages
TypeScript (100%)
Developer
aleclarson
Download Statistics
Total Downloads
147,591,794
Last Day
318,514
Last Week
2,370,966
Last Month
10,501,641
Last Year
100,091,624
GitHub Statistics
1,363 Stars
262 Commits
51 Forks
5 Watching
7 Branches
26 Contributors
Package Meta Information
Latest Version
5.1.4
Package Id
vite-tsconfig-paths@5.1.4
Unpacked Size
67.32 kB
Size
19.05 kB
File Count
12
NPM Version
10.9.0
Node Version
23.1.0
Publised On
06 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
147,591,794
Last day
-35.1%
318,514
Compared to previous day
Last week
-10.3%
2,370,966
Compared to previous week
Last month
5.1%
10,501,641
Compared to previous month
Last year
153.2%
100,091,624
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
👋 Check out Radashi, my latest endeavor.
vite-tsconfig-paths
Give vite
the ability to resolve imports using TypeScript's path mapping.
Usage
-
Install as dev dependency
-
Ensure the project either has
"type": "module"
set or that the Vite config is renamed tovite.config.mjs
/vite.config.mts
depending on whether TypeScript is used -
Inject
vite-tsconfig-paths
in the Vite config1import { defineConfig } from 'vite' 2import tsconfigPaths from 'vite-tsconfig-paths' 3 4export default defineConfig({ 5 plugins: [tsconfigPaths()], 6})
-
(optional) ⚠️ To enable path resolution in non-TypeScript modules (e.g.
.vue
,.svelte
,.mdx
), you must set theallowJs
option to true in yourtsconfig.json
file. If that doesn't work, you might need to enableloose: true
to resolve all files. Note that, due to a Vite limitation, CSS files (and CSS dialects) cannot be resolved with this plugin (see #30).
Note: You need to restart Vite when you update your paths
mappings. This is being tracked in #17 (contributions welcome).
Options
-
root: string
The directory to search fortsconfig.json
files.The default value of this option depends on whether
projects
is defined. If it is, then the Vite project root is used. Otherwise, Vite'ssearchForWorkspaceRoot
function is used. -
projects: string[]
If you have an esoteric setup, you might need this option to specify where your tsconfig files are located. The paths within are relative to theroot
option.If defined, the
root
directory won't be searched for tsconfig files. You should always try using just theroot
option first, because this option is more brittle. -
loose: boolean
Disable strictness that limits path resolution to TypeScript and JavaScript importers.Useful if you want imports in Vue templates to be resolved, but don't want to use
allowJs
in your tsconfig, for example.In other words, when
loose: true
is used, any file that gets transpiled into JavaScript will have its imports resolved by this plugin. -
parseNative: boolean
Enable use of thetsconfck.parseNative
function, which delegates the loading of tsconfig files to the TypeScript compiler. You'll probably never need this, but I added it just in case.⚠️ This option can slow down Vite's startup time by as much as 600ms, due to the size of the TypeScript compiler. Only use it when necessary.
-
ignoreConfigErrors: boolean
When true, parsing errors encountered while loading tsconfig files will be ignored. This is useful if you have a monorepo with multiple tsconfig files, and you don't want to see errors for the ones that aren't relevant to the current project. -
skip: (dir: string) => boolean
A function that determines which directories to skip when searching for tsconfig.json files. While.git
andnode_modules
directories are always skipped, this option allows you to skip additional directories, which is useful in large monorepos to improve performance.
allowJs
If your tsconfig file has "allowJs": true
in it, path resolution will be expanded beyond TypeScript importers. The following extensions will have their imports resolved by this plugin: .vue
, .svelte
, .mdx
, .mjs
, .js
, .jsx
baseUrl
If the baseUrl
is defined, it gets prepended to all bare imports, and its resolution will take precedence over node_modules. This is also how TypeScript does it.
Say the baseUrl
is ../root
and you import react
. This plugin will use ../root/react
if it exists. If not found, then react
is resolved normally. The baseUrl
is relative to the project root (where tsconfig.json
lives).
include/exclude
The include
and exclude
tsconfig options are respected.
Internally, globrex is used for glob matching.
Troubleshooting
The DEBUG
environment variable can be used to figure out why this plugin isn't working as you may have expected.
1DEBUG=vite-tsconfig-paths yarn vite
Also, check out the Troubleshooting wiki page for more guidance.
No vulnerabilities found.
Reason
29 commit(s) and 22 issue activity found in the last 90 days -- score normalized to 10
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 4/30 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 4 are checked with a SAST tool
Reason
16 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-c24v-8rfc-w8vw
- Warn: Project is vulnerable to: GHSA-8jhw-289h-jh2g
- Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3
- Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
Score
4
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to vite-tsconfig-paths
@fwouts/vite-tsconfig-paths
Vite resolver for TypeScript compilerOptions.paths
vite-plugin-tsconfig-paths
Vite plugin for resolving tsconfig paths
vite-resolve-tsconfig-paths
A Vite plugin that resolves TypeScript compilerOptions.paths.
vitest-tsconfig-paths
Vitest resolver for TypeScript compilerOptions.paths