Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 4c3e8a3

Browse files
authored
Add warning for older TypeScript versions (vercel#25867)
1 parent e4e7217 commit 4c3e8a3

File tree

6 files changed

+116
-0
lines changed

6 files changed

+116
-0
lines changed

packages/next/lib/verifyTypeScriptSetup.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import {
44
hasNecessaryDependencies,
55
NecessaryDependencies,
66
} from './has-necessary-dependencies'
7+
import semver from 'next/dist/compiled/semver'
78
import { CompileError } from './compile-error'
89
import { FatalError } from './fatal-error'
10+
import * as log from '../build/output/log'
911

1012
import { getTypeScriptIntent } from './typescript/getTypeScriptIntent'
1113
import { TypeCheckResult } from './typescript/runTypeCheck'
@@ -38,6 +40,12 @@ export async function verifyTypeScriptSetup(
3840
// Load TypeScript after we're sure it exists:
3941
const ts = (await import(deps.resolved)) as typeof import('typescript')
4042

43+
if (semver.lt(ts.version, '4.3.2')) {
44+
log.warn(
45+
`Minimum recommended TypeScript version is v4.3.2, older versions can potentially be incompatible with Next.js. Detected: ${ts.version}`
46+
)
47+
}
48+
4149
// Reconfigure (or create) the user's `tsconfig.json` for them:
4250
await writeConfigurationDefaults(ts, tsConfigPath, firstTimeSetup)
4351
// Write out the necessary `next-env.d.ts` file to correctly register

test/integration/typescript-version-warning/app/node_modules/typescript/index.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/typescript-version-warning/app/node_modules/typescript/package.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page(props) {
2+
return <p>hello world</p>
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"skipLibCheck": true,
7+
"strict": false,
8+
"forceConsistentCasingInFileNames": true,
9+
"noEmit": true,
10+
"esModuleInterop": true,
11+
"module": "esnext",
12+
"moduleResolution": "node",
13+
"resolveJsonModule": true,
14+
"isolatedModules": true,
15+
"jsx": "preserve"
16+
},
17+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
18+
"exclude": ["node_modules"]
19+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* eslint-env jest */
2+
import fs from 'fs-extra'
3+
import { join } from 'path'
4+
import { nextBuild, findPort, launchApp, killApp } from 'next-test-utils'
5+
6+
jest.setTimeout(1000 * 60 * 2)
7+
8+
const appDir = join(__dirname, '../app')
9+
10+
describe('Minimum TypeScript Warning', () => {
11+
it('should show warning during next build with old version', async () => {
12+
const res = await nextBuild(appDir, [], {
13+
stderr: true,
14+
stdout: true,
15+
})
16+
expect(res.stdout + res.stderr).toContain(
17+
'Minimum recommended TypeScript version is'
18+
)
19+
})
20+
21+
it('should show warning during next dev with old version', async () => {
22+
let output = ''
23+
24+
const handleOutput = (msg) => {
25+
output += msg
26+
}
27+
const app = await launchApp(appDir, await findPort(), {
28+
onStdout: handleOutput,
29+
onStderr: handleOutput,
30+
})
31+
await killApp(app)
32+
33+
expect(output).toContain('Minimum recommended TypeScript version is')
34+
})
35+
36+
it('should not show warning during next build with new version', async () => {
37+
await fs.rename(
38+
join(appDir, 'node_modules/typescript'),
39+
join(appDir, 'node_modules/typescript-back')
40+
)
41+
const res = await nextBuild(appDir, [], {
42+
stderr: true,
43+
stdout: true,
44+
})
45+
await fs.rename(
46+
join(appDir, 'node_modules/typescript-back'),
47+
join(appDir, 'node_modules/typescript')
48+
)
49+
expect(res.stdout + res.stderr).toContain(
50+
'Minimum recommended TypeScript version is'
51+
)
52+
})
53+
54+
it('should not show warning during next dev with new version', async () => {
55+
let output = ''
56+
57+
const handleOutput = (msg) => {
58+
output += msg
59+
}
60+
await fs.rename(
61+
join(appDir, 'node_modules/typescript'),
62+
join(appDir, 'node_modules/typescript-back')
63+
)
64+
const app = await launchApp(appDir, await findPort(), {
65+
onStdout: handleOutput,
66+
onStderr: handleOutput,
67+
})
68+
await killApp(app)
69+
await fs.rename(
70+
join(appDir, 'node_modules/typescript-back'),
71+
join(appDir, 'node_modules/typescript')
72+
)
73+
74+
expect(output).toContain('Minimum recommended TypeScript version is')
75+
})
76+
})

0 commit comments

Comments
 (0)