Skip to content

Commit 3460fc5

Browse files
authored
fix(resolve): resolve tsconfig paths starting with # (#22038)
1 parent 05803be commit 3460fc5

5 files changed

Lines changed: 14 additions & 1 deletion

File tree

packages/vite/src/node/plugins/resolve.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ function resolveSubpathImports(
516516
}
517517
}
518518

519+
if (importsPath == null) return
519520
return importsPath + postfix
520521
}
521522

playground/resolve-tsconfig-paths/__tests__/resolve.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ test('import from .js', async () => {
99
await expect.poll(() => page.textContent('.js')).toMatch('[success]')
1010
})
1111

12+
test('import using # prefixed path', async () => {
13+
await expect.poll(() => page.textContent('.hash')).toMatch('[success]')
14+
})
15+
1216
test('fallback works', async () => {
1317
await expect.poll(() => page.textContent('.fallback')).toMatch('[success]')
1418
})

playground/resolve-tsconfig-paths/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ <h2>Import from .js</h2>
99
<h2>Fallback works</h2>
1010
<p class="fallback"></p>
1111

12+
<h2>Import using # prefixed path</h2>
13+
<p class="hash"></p>
14+
1215
<h2>Nested tsconfig.json & references / include works</h2>
1316
<p class="nested-a"></p>
1417
<p class="nested-b"></p>
@@ -27,6 +30,9 @@ <h2>Nested tsconfig.json & references / include works</h2>
2730
import fallback from '@fallback/fallback'
2831
text('.fallback', fallback)
2932

33+
import hash from './src/hash.ts'
34+
text('.hash', hash)
35+
3036
import { valueA, valueB } from './src/nested/index.ts'
3137
text('.nested-a', valueA)
3238
text('.nested-b', valueB)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from '#/imported'

playground/resolve-tsconfig-paths/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"noEmit": true,
55
"paths": {
66
"@/*": ["./src/*"],
7-
"@fallback/*": ["./src/*", "./fallback/*"]
7+
"@fallback/*": ["./src/*", "./fallback/*"],
8+
"#/*": ["./src/*"]
89
}
910
},
1011
"exclude": ["./__tests__"]

0 commit comments

Comments
 (0)