Skip to content

Commit 1a0b5d2

Browse files
styflekvnwolf
andauthored
fix: moduleResolution: bundler support in tsconfig.json (#51065)
- Fixes #47858 - Closes #50289 fix #47858 fix NEXT-1281 Co-authored-by: Kevin Wolf <3157426+kevinwolfcr@users.noreply.github.com>
1 parent 90ee958 commit 1a0b5d2

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function getDesiredCompilerOptions(
6969
(ts.ModuleResolutionKind as any).Node12,
7070
ts.ModuleResolutionKind.Node16,
7171
ts.ModuleResolutionKind.NodeNext,
72+
ts.ModuleResolutionKind.Bundler,
7273
].filter((val) => typeof val !== 'undefined'),
7374
value: 'node',
7475
reason: 'to match webpack resolution',

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,62 @@ describe('tsconfig.json verifier', () => {
354354
`)
355355
})
356356

357+
it('allows you to set bundler moduleResolution mode', async () => {
358+
expect(await exists(tsConfig)).toBe(false)
359+
360+
await writeFile(
361+
tsConfig,
362+
`{ "compilerOptions": { "esModuleInterop": false, "moduleResolution": "bundler" } }`
363+
)
364+
await new Promise((resolve) => setTimeout(resolve, 500))
365+
const { code, stderr, stdout } = await nextBuild(appDir, undefined, {
366+
stderr: true,
367+
stdout: true,
368+
})
369+
expect(stderr + stdout).not.toContain('moduleResolution')
370+
expect(code).toBe(0)
371+
372+
expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
373+
"{
374+
\\"compilerOptions\\": {
375+
\\"esModuleInterop\\": true,
376+
\\"moduleResolution\\": \\"bundler\\",
377+
\\"lib\\": [
378+
\\"dom\\",
379+
\\"dom.iterable\\",
380+
\\"esnext\\"
381+
],
382+
\\"allowJs\\": true,
383+
\\"skipLibCheck\\": true,
384+
\\"strict\\": false,
385+
\\"forceConsistentCasingInFileNames\\": true,
386+
\\"noEmit\\": true,
387+
\\"incremental\\": true,
388+
\\"module\\": \\"esnext\\",
389+
\\"resolveJsonModule\\": true,
390+
\\"isolatedModules\\": true,
391+
\\"jsx\\": \\"preserve\\",
392+
\\"plugins\\": [
393+
{
394+
\\"name\\": \\"next\\"
395+
}
396+
],
397+
\\"strictNullChecks\\": true
398+
},
399+
\\"include\\": [
400+
\\"next-env.d.ts\\",
401+
\\".next/types/**/*.ts\\",
402+
\\"**/*.ts\\",
403+
\\"**/*.tsx\\"
404+
],
405+
\\"exclude\\": [
406+
\\"node_modules\\"
407+
]
408+
}
409+
"
410+
`)
411+
})
412+
357413
it('allows you to set target mode', async () => {
358414
expect(await exists(tsConfig)).toBe(false)
359415

0 commit comments

Comments
 (0)