From 51c0a4a26882e6ad1025e4b4c57d070339022060 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 15 Apr 2022 09:34:49 -0400 Subject: [PATCH 1/5] Add suppport for tsconfig moduleResolution `node | node12 | nodenext` --- .../typescript/writeConfigurationDefaults.ts | 6 +++ .../tsconfig-verifier/test/index.test.js | 45 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/packages/next/lib/typescript/writeConfigurationDefaults.ts b/packages/next/lib/typescript/writeConfigurationDefaults.ts index 04333a8b33eae..35b6c26c82213 100644 --- a/packages/next/lib/typescript/writeConfigurationDefaults.ts +++ b/packages/next/lib/typescript/writeConfigurationDefaults.ts @@ -50,6 +50,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', }, diff --git a/test/integration/tsconfig-verifier/test/index.test.js b/test/integration/tsconfig-verifier/test/index.test.js index d5762e6ecaf52..5ee393ae3f231 100644 --- a/test/integration/tsconfig-verifier/test/index.test.js +++ b/test/integration/tsconfig-verifier/test/index.test.js @@ -261,6 +261,51 @@ 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, + \\"module\\": \\"es2020\\", + \\"target\\": \\"es5\\", + \\"lib\\": [ + \\"dom\\", + \\"dom.iterable\\", + \\"esnext\\" + ], + \\"allowJs\\": true, + \\"skipLibCheck\\": true, + \\"strict\\": false, + \\"forceConsistentCasingInFileNames\\": true, + \\"noEmit\\": true, + \\"moduleResolution\\": \\"node12\\", + \\"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) From 83e7a39e53e6c08388066678f7ec54f0063c65e5 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 15 Apr 2022 09:57:05 -0400 Subject: [PATCH 2/5] Fix test --- test/integration/tsconfig-verifier/test/index.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/integration/tsconfig-verifier/test/index.test.js b/test/integration/tsconfig-verifier/test/index.test.js index 89791f8b2d79c..9b994e7a5199f 100644 --- a/test/integration/tsconfig-verifier/test/index.test.js +++ b/test/integration/tsconfig-verifier/test/index.test.js @@ -279,7 +279,7 @@ describe('tsconfig.json verifier', () => { "{ \\"compilerOptions\\": { \\"esModuleInterop\\": true, - \\"module\\": \\"es2020\\", + \\"moduleResolution\\": \\"node12\\", \\"target\\": \\"es5\\", \\"lib\\": [ \\"dom\\", @@ -291,7 +291,8 @@ describe('tsconfig.json verifier', () => { \\"strict\\": false, \\"forceConsistentCasingInFileNames\\": true, \\"noEmit\\": true, - \\"moduleResolution\\": \\"node12\\", + \\"incremental\\": true, + \\"module\\": \\"esnext\\", \\"resolveJsonModule\\": true, \\"isolatedModules\\": true, \\"jsx\\": \\"preserve\\" From 7ccd2f4e52624f55f99aa76f282fcd579e08b0d7 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 15 Apr 2022 09:57:14 -0400 Subject: [PATCH 3/5] Bump typescript to latest version --- package.json | 2 +- packages/next/server/web/utils.ts | 1 - yarn.lock | 8 ++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 42ab470b3d61d..e675dcd7ac017 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/next/server/web/utils.ts b/packages/next/server/web/utils.ts index 864721bb3ab40..6f1b1240e9dbd 100644 --- a/packages/next/server/web/utils.ts +++ b/packages/next/server/web/utils.ts @@ -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 } ) } diff --git a/yarn.lock b/yarn.lock index b3c97dc2ad5d3..ab656e1e47a63 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" From 0796a648a3d1c027e96645d9a040012a18835592 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 15 Apr 2022 10:37:15 -0500 Subject: [PATCH 4/5] fix extra define.amd --- packages/next/taskfile.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/next/taskfile.js b/packages/next/taskfile.js index 64406648313ce..ab0b3ffa521b1 100644 --- a/packages/next/taskfile.js +++ b/packages/next/taskfile.js @@ -196,7 +196,13 @@ export async function ncc_next__react_dev_overlay(task, opts) { 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' + ), '' ) ) From 48adb9d96a9eb47581823bb213af2983d010f9b5 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Fri, 15 Apr 2022 10:50:45 -0500 Subject: [PATCH 5/5] update comment --- packages/next/taskfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/taskfile.js b/packages/next/taskfile.js index ab0b3ffa521b1..42f2d459ffed8 100644 --- a/packages/next/taskfile.js +++ b/packages/next/taskfile.js @@ -192,7 +192,7 @@ 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(