diff --git a/package.json b/package.json index 42ab470b3d61dd9..e675dcd7ac017dd 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/lib/typescript/writeConfigurationDefaults.ts b/packages/next/lib/typescript/writeConfigurationDefaults.ts index bc67874936d71d5..c534f63154ebb49 100644 --- a/packages/next/lib/typescript/writeConfigurationDefaults.ts +++ b/packages/next/lib/typescript/writeConfigurationDefaults.ts @@ -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', }, diff --git a/packages/next/server/web/utils.ts b/packages/next/server/web/utils.ts index 864721bb3ab40c1..6f1b1240e9dbd2a 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/packages/next/taskfile.js b/packages/next/taskfile.js index 64406648313ce35..42f2d459ffed8bf 100644 --- a/packages/next/taskfile.js +++ b/packages/next/taskfile.js @@ -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' + ), '' ) ) diff --git a/test/integration/tsconfig-verifier/test/index.test.js b/test/integration/tsconfig-verifier/test/index.test.js index 799ca2403d2942e..9b994e7a5199fd1 100644 --- a/test/integration/tsconfig-verifier/test/index.test.js +++ b/test/integration/tsconfig-verifier/test/index.test.js @@ -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) diff --git a/yarn.lock b/yarn.lock index f39f13de5b430fb..d71d22a4ba6ac67 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"