Unverified Commit fe19e10c authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Turbopack: Don't resolve tsconfig relative to file (#83484)

## What?

Changes in #83331 accidentally changed behavior of how `tsconfig.json`
is resolved. When using Next.js we don't want it to be resolved relative
to the current file being compiled. It should only use the application
root.

This PR fixes the behavior to match what it was before and adds a test
that fails if it breaks again.
parent 900d344f
......@@ -188,6 +188,9 @@ pub async fn get_client_resolve_options_context(
.typescript_tsconfig_path()
.await?
.as_ref()
// Fall back to tsconfig only for resolving. This is because we don't want Turbopack to
// resolve tsconfig.json relative to the file being compiled.
.or(Some(&RcStr::from("tsconfig.json")))
.map(|p| project_path.join(p))
.transpose()?;
......
......@@ -192,6 +192,9 @@ pub async fn get_edge_resolve_options_context(
.typescript_tsconfig_path()
.await?
.as_ref()
// Fall back to tsconfig only for resolving. This is because we don't want Turbopack to
// resolve tsconfig.json relative to the file being compiled.
.or(Some(&RcStr::from("tsconfig.json")))
.map(|p| project_path.join(p))
.transpose()?,
rules: vec![(
......
......@@ -333,6 +333,9 @@ pub async fn get_server_resolve_options_context(
.typescript_tsconfig_path()
.await?
.as_ref()
// Fall back to tsconfig only for resolving. This is because we don't want Turbopack to
// resolve tsconfig.json relative to the file being compiled.
.or(Some(&RcStr::from("tsconfig.json")))
.map(|p| project_path.join(p))
.transpose()?;
......
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>hello world</p>
}
// This file shouldn't be found by Turbopack.
{
"extends": "non-existent-package"
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
import { nextTestSetup } from 'e2e-utils'
describe('tsconfig-no-relative-resolve', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
})
// Next.js should only use the application root tsconfig.json file and not files relative to the file being compiled.
it('should fail to build', async () => {
const { exitCode, cliOutput } = await next.build()
expect(exitCode).toBe(0)
expect(cliOutput).not.toContain('non-existent-package')
})
})
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment