Skip to content

Commit e75c366

Browse files
fix: don't add isolateModules to tsconfig when extending from tsconfig with verbatimModuleSyntax (#54164)
<!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # --> this is a follow-up to #48018 (don't add `isolatedModules: true` to `tsconfig.json` when `verbatimModuleSyntax: true` is set), which also handles the case where `verbatimModuleSyntax: true` is set in a base tsconfig which is being referenced via `tsconfig#extends`. --------- Co-authored-by: Zack Tanner <[email protected]>
1 parent 542f080 commit e75c366

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

packages/next/src/lib/typescript/writeConfigurationDefaults.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type DesiredCompilerOptionsShape = {
2020

2121
function getDesiredCompilerOptions(
2222
ts: typeof import('typescript'),
23-
userTsConfig?: { compilerOptions?: CompilerOptions }
23+
tsOptions?: CompilerOptions
2424
): DesiredCompilerOptionsShape {
2525
const o: DesiredCompilerOptionsShape = {
2626
// These are suggested values and will be set when not present in the
@@ -80,7 +80,7 @@ function getDesiredCompilerOptions(
8080
reason: 'to match webpack resolution',
8181
},
8282
resolveJsonModule: { value: true, reason: 'to match webpack resolution' },
83-
...(userTsConfig?.compilerOptions?.verbatimModuleSyntax === true
83+
...(tsOptions?.verbatimModuleSyntax === true
8484
? undefined
8585
: {
8686
isolatedModules: {
@@ -139,7 +139,7 @@ export async function writeConfigurationDefaults(
139139
isFirstTimeSetup = true
140140
}
141141

142-
const desiredCompilerOptions = getDesiredCompilerOptions(ts, userTsConfig)
142+
const desiredCompilerOptions = getDesiredCompilerOptions(ts, tsOptions)
143143

144144
const suggestedActions: string[] = []
145145
const requiredActions: string[] = []

test/integration/tsconfig-verifier/test/index.test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,63 @@ import path from 'path'
567567
`)
568568
})
569569

570+
it('allows you to set verbatimModuleSyntax true via extends without adding isolatedModules', async () => {
571+
expect(await exists(tsConfig)).toBe(false)
572+
expect(await exists(tsConfigBase)).toBe(false)
573+
574+
await writeFile(
575+
tsConfigBase,
576+
`{ "compilerOptions": { "verbatimModuleSyntax": true } }`
577+
)
578+
await writeFile(tsConfig, `{ "extends": "./tsconfig.base.json" }`)
579+
await new Promise((resolve) => setTimeout(resolve, 500))
580+
const { code, stderr, stdout } = await nextBuild(appDir, undefined, {
581+
stderr: true,
582+
stdout: true,
583+
})
584+
expect(stderr + stdout).not.toContain('isolatedModules')
585+
expect(code).toBe(0)
586+
587+
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
588+
"{
589+
\\"extends\\": \\"./tsconfig.base.json\\",
590+
\\"compilerOptions\\": {
591+
\\"lib\\": [
592+
\\"dom\\",
593+
\\"dom.iterable\\",
594+
\\"esnext\\"
595+
],
596+
\\"allowJs\\": true,
597+
\\"skipLibCheck\\": true,
598+
\\"strict\\": false,
599+
\\"noEmit\\": true,
600+
\\"incremental\\": true,
601+
\\"esModuleInterop\\": true,
602+
\\"module\\": \\"esnext\\",
603+
\\"moduleResolution\\": \\"node\\",
604+
\\"resolveJsonModule\\": true,
605+
\\"jsx\\": \\"preserve\\",
606+
\\"plugins\\": [
607+
{
608+
\\"name\\": \\"next\\"
609+
}
610+
],
611+
\\"strictNullChecks\\": true
612+
},
613+
\\"include\\": [
614+
\\"next-env.d.ts\\",
615+
\\".next/types/**/*.ts\\",
616+
\\"**/*.ts\\",
617+
\\"**/*.tsx\\"
618+
],
619+
\\"exclude\\": [
620+
\\"node_modules\\"
621+
]
622+
}
623+
"
624+
`)
625+
})
626+
570627
it('allows you to extend another configuration file', async () => {
571628
expect(await exists(tsConfig)).toBe(false)
572629
expect(await exists(tsConfigBase)).toBe(false)

0 commit comments

Comments
 (0)