Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tsconfig moduleResolution node | node12 | nodenext #36189

Merged
merged 9 commits into from Apr 15, 2022
Merged
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -167,7 +167,7 @@
"tree-kill": "1.2.2",
"tsec": "0.2.1",
"turbo": "1.0.28",
"typescript": "4.5.5",
"typescript": "4.6.3",
"wait-port": "0.2.2",
"web-streams-polyfill": "2.1.1",
"webpack": "link:./node_modules/webpack5",
Expand Down
6 changes: 6 additions & 0 deletions packages/next/lib/typescript/writeConfigurationDefaults.ts
Expand Up @@ -54,6 +54,12 @@ function getDesiredCompilerOptions(
},
moduleResolution: {
parsedValue: ts.ModuleResolutionKind.NodeJs,
// All of these values work:
parsedValues: [
ts.ModuleResolutionKind.NodeJs,
ts.ModuleResolutionKind.Node12,
ts.ModuleResolutionKind.NodeNext,
],
value: 'node',
reason: 'to match webpack resolution',
},
Expand Down
1 change: 0 additions & 1 deletion packages/next/server/web/utils.ts
Expand Up @@ -131,7 +131,6 @@ export function validateURL(url: string | URL): string {
} catch (error: any) {
throw new Error(
`URLs is malformed. Please use only absolute URLs - https://nextjs.org/docs/messages/middleware-relative-urls`,
// @ts-expect-error This will work for people who enable the error causes polyfill
{ cause: error }
)
}
Expand Down
46 changes: 46 additions & 0 deletions test/integration/tsconfig-verifier/test/index.test.js
Expand Up @@ -264,6 +264,52 @@ describe('tsconfig.json verifier', () => {
`)
})

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

await writeFile(
tsConfig,
`{ "compilerOptions": { "esModuleInterop": false, "moduleResolution": "node12" } }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { code } = await nextBuild(appDir)
expect(code).toBe(0)

expect(await readFile(tsConfig, 'utf8')).toMatchInlineSnapshot(`
"{
\\"compilerOptions\\": {
\\"esModuleInterop\\": true,
\\"moduleResolution\\": \\"node12\\",
\\"target\\": \\"es5\\",
\\"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\\"
},
\\"include\\": [
\\"next-env.d.ts\\",
\\"**/*.ts\\",
\\"**/*.tsx\\"
],
\\"exclude\\": [
\\"node_modules\\"
]
}
"
`)
})

it('allows you to extend another configuration file', async () => {
expect(await exists(tsConfig)).toBe(false)
expect(await exists(tsConfigBase)).toBe(false)
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -20667,10 +20667,10 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@4.5.5:
version "4.5.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3"
integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==
typescript@4.6.3:
version "4.6.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.3.tgz#eefeafa6afdd31d725584c67a0eaba80f6fc6c6c"
integrity sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==

typescript@^4.1.3:
version "4.1.3"
Expand Down