Skip to content

Commit

Permalink
fix: moduleResolution: bundler support in tsconfig.json (#51065)
Browse files Browse the repository at this point in the history
- Fixes #47858
- Closes #50289

fix #47858
fix NEXT-1281

Co-authored-by: Kevin Wolf <3157426+kevinwolfcr@users.noreply.github.com>
  • Loading branch information
styfle and kevinwolfcr committed Jun 9, 2023
1 parent 90ee958 commit 1a0b5d2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function getDesiredCompilerOptions(
(ts.ModuleResolutionKind as any).Node12,
ts.ModuleResolutionKind.Node16,
ts.ModuleResolutionKind.NodeNext,
ts.ModuleResolutionKind.Bundler,
].filter((val) => typeof val !== 'undefined'),
value: 'node',
reason: 'to match webpack resolution',
Expand Down
56 changes: 56 additions & 0 deletions test/integration/tsconfig-verifier/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,62 @@ describe('tsconfig.json verifier', () => {
`)
})

it('allows you to set bundler moduleResolution mode', async () => {
expect(await exists(tsConfig)).toBe(false)

await writeFile(
tsConfig,
`{ "compilerOptions": { "esModuleInterop": false, "moduleResolution": "bundler" } }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { code, stderr, stdout } = await nextBuild(appDir, undefined, {
stderr: true,
stdout: true,
})
expect(stderr + stdout).not.toContain('moduleResolution')
expect(code).toBe(0)

expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
\\"compilerOptions\\": {
\\"esModuleInterop\\": true,
\\"moduleResolution\\": \\"bundler\\",
\\"lib\\": [
\\"dom\\",
\\"dom.iterable\\",
\\"esnext\\"
],
\\"allowJs\\": true,
\\"skipLibCheck\\": true,
\\"strict\\": false,
\\"forceConsistentCasingInFileNames\\": true,
\\"noEmit\\": true,
\\"incremental\\": true,
\\"module\\": \\"esnext\\",
\\"resolveJsonModule\\": true,
\\"isolatedModules\\": true,
\\"jsx\\": \\"preserve\\",
\\"plugins\\": [
{
\\"name\\": \\"next\\"
}
],
\\"strictNullChecks\\": true
},
\\"include\\": [
\\"next-env.d.ts\\",
\\".next/types/**/*.ts\\",
\\"**/*.ts\\",
\\"**/*.tsx\\"
],
\\"exclude\\": [
\\"node_modules\\"
]
}
"
`)
})

it('allows you to set target mode', async () => {
expect(await exists(tsConfig)).toBe(false)

Expand Down

0 comments on commit 1a0b5d2

Please sign in to comment.