Unverified Commit 4c15f89b authored by Steven's avatar Steven Committed by GitHub

Add support for tsconfig moduleResolution `node | node12 | nodenext` (#36189)

- Fixes #35572 
Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent 1c20d3d0
......@@ -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",
......
......@@ -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',
},
......
......@@ -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 }
)
}
......
......@@ -192,11 +192,17 @@ export async function ncc_next__react_dev_overlay(task, opts) {
)
const content = fs.readFileSync(clientFile, 'utf8')
// remove AMD define branch as this forces the module to not
// be treated as commonjs in serverless mode
// be treated as commonjs in serverless/client mode
fs.writeFileSync(
clientFile,
content.replace(
'if(typeof define=="function"&&typeof define.amd=="object"&&define.amd){r.platform=v;define((function(){return v}))}else ',
new RegExp(
'if(typeof define=="function"&&typeof define.amd=="object"&&define.amd){r.platform=b;define((function(){return b}))}else '.replace(
/[|\\{}()[\]^$+*?.-]/g,
'\\$&'
),
'g'
),
''
)
)
......
......@@ -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)
......
......@@ -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"
......
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