Skip to content

Commit 1db933a

Browse files
authored
fallback to normal resolving if alias doesn't resolve (#7778)
### Description fixes vercel/next.js#62037 ### Testing Instructions <!-- Give a quick description of steps to test your changes. --> Closes PACK-2800
1 parent 043544e commit 1db933a

File tree

9 files changed

+44
-1
lines changed

9 files changed

+44
-1
lines changed

crates/turbopack-core/src/resolve/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,9 @@ async fn resolve_internal_inline(
15131513
// Typescript resolution algorithm does in case an alias match
15141514
// doesn't resolve to anything: fall back to resolving the request normally.
15151515
if let Some(result) = resolved_result {
1516-
return Ok(result);
1516+
if !*result.is_unresolveable().await? {
1517+
return Ok(result);
1518+
}
15171519
}
15181520
}
15191521
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import foo from "@foo";
2+
import fooBar from "@foo/bar";
3+
import bazFoo from "@baz/foo";
4+
import srcBazFoo from "@src/baz/foo";
5+
6+
it("should resolve an alias to a local file", () => {
7+
expect(foo).toBe("foo");
8+
expect(require("@foo")).toHaveProperty("default", "foo");
9+
});
10+
11+
it("should fallback from an alias", () => {
12+
expect(fooBar).toBe("@foo/bar");
13+
expect(require("@foo/bar")).toHaveProperty("default", "@foo/bar");
14+
});
15+
16+
it("should prefer alias over normal resolving", () => {
17+
expect(bazFoo).toBe("baz/foo");
18+
expect(require("@baz/foo")).toHaveProperty("default", "baz/foo");
19+
});
20+
21+
it("should resolve the alternative alias value", () => {
22+
expect(srcBazFoo).toBe("baz/foo");
23+
expect(require("@src/baz/foo")).toHaveProperty("default", "baz/foo");
24+
});

crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-fallback/input/node_modules/@baz/foo/index.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-fallback/input/node_modules/@baz/foo/package.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-fallback/input/node_modules/@foo/bar/index.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/turbopack-tests/tests/execution/turbopack/resolving/tsconfig-fallback/input/node_modules/@foo/bar/package.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "baz/foo";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "foo";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"paths": {
4+
"@*": ["./src/*", "./*"]
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)