Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
59ce87e5
Unverified
Commit
59ce87e5
authored
May 23, 2024
by
Sebastian Silbermann
Committed by
GitHub
May 23, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't fail the build if `@types/` packages appear to be missing (#66127)
Co-authored-by:
Alessio Gravili
<
alessio@gravili.de
>
parent
3a1d3f84
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
12 deletions
+90
-12
verify-typescript-setup.ts
packages/next/src/lib/verify-typescript-setup.ts
+43
-12
index.test.ts
test/production/ci-missing-typescript-deps/index.test.ts
+47
-0
No files found.
packages/next/src/lib/verify-typescript-setup.ts
View file @
59ce87e5
...
@@ -2,7 +2,10 @@ import { bold, cyan, red, yellow } from './picocolors'
...
@@ -2,7 +2,10 @@ import { bold, cyan, red, yellow } from './picocolors'
import
path
from
'path'
import
path
from
'path'
import
{
hasNecessaryDependencies
}
from
'./has-necessary-dependencies'
import
{
hasNecessaryDependencies
}
from
'./has-necessary-dependencies'
import
type
{
NecessaryDependencies
}
from
'./has-necessary-dependencies'
import
type
{
MissingDependency
,
NecessaryDependencies
,
}
from
'./has-necessary-dependencies'
import
semver
from
'next/dist/compiled/semver'
import
semver
from
'next/dist/compiled/semver'
import
{
CompileError
}
from
'./compile-error'
import
{
CompileError
}
from
'./compile-error'
import
*
as
log
from
'../build/output/log'
import
*
as
log
from
'../build/output/log'
...
@@ -69,11 +72,37 @@ export async function verifyTypeScriptSetup({
...
@@ -69,11 +72,37 @@ export async function verifyTypeScriptSetup({
requiredPackages
requiredPackages
)
)
if
(
deps
.
missing
?.
length
>
0
)
{
const
missingTypeDeps
:
MissingDependency
[]
=
[]
const
missingDepsExceptTypes
:
MissingDependency
[]
=
[]
for
(
const
dep
of
deps
.
missing
)
{
if
(
dep
.
pkg
.
startsWith
(
'@types/'
))
{
missingTypeDeps
.
push
(
dep
)
}
else
{
missingDepsExceptTypes
.
push
(
dep
)
}
}
// Just warn for potentially missing type deps.
// TODO: Fix false-positive in `hasNecessaryDependencies` when `overrides` are used in package managers
if
(
missingTypeDeps
.
length
>
0
)
{
console
.
log
(
bold
(
yellow
(
`It looks like you're trying to use TypeScript but do not have the required type package(s) installed.`
)
)
+
'
\
n'
+
'This may be a bug in Next.js. Please file an issue.
\
n'
+
'Make sure the following type packages are installed:
\
n'
+
missingTypeDeps
.
map
((
dep
)
=>
`
${
cyan
(
dep
.
pkg
)}
`
).
join
(
'
\
n'
)
)
}
if
(
missingDepsExceptTypes
.
length
>
0
)
{
if
(
isCI
)
{
if
(
isCI
)
{
// we don't attempt auto install in CI to avoid side-effects
// we don't attempt auto install in CI to avoid side-effects
// and instead log the error for installing needed packages
// and instead log the error for installing needed packages
missingDepsError
(
dir
,
deps
.
missing
)
missingDepsError
(
dir
,
missingDepsExceptTypes
)
}
}
console
.
log
(
console
.
log
(
bold
(
bold
(
...
@@ -91,16 +120,18 @@ export async function verifyTypeScriptSetup({
...
@@ -91,16 +120,18 @@ export async function verifyTypeScriptSetup({
)
+
)
+
'
\
n'
'
\
n'
)
)
await
installDependencies
(
dir
,
deps
.
missing
,
true
).
catch
((
err
)
=>
{
await
installDependencies
(
dir
,
missingDepsExceptTypes
,
true
).
catch
(
if
(
err
&&
typeof
err
===
'object'
&&
'command'
in
err
)
{
(
err
)
=>
{
console
.
error
(
if
(
err
&&
typeof
err
===
'object'
&&
'command'
in
err
)
{
`Failed to install required TypeScript dependencies, please install them manually to continue:\n`
+
console
.
error
(
(
err
as
any
).
command
+
`Failed to install required TypeScript dependencies, please install them manually to continue:\n`
+
'
\
n'
(
err
as
any
).
command
+
)
'
\
n'
)
}
throw
err
}
}
throw
err
)
})
deps
=
await
hasNecessaryDependencies
(
dir
,
requiredPackages
)
deps
=
await
hasNecessaryDependencies
(
dir
,
requiredPackages
)
}
}
...
...
test/production/ci-missing-typescript-deps/index.test.ts
View file @
59ce87e5
...
@@ -35,4 +35,51 @@ describe('ci-missing-typescript-deps', () => {
...
@@ -35,4 +35,51 @@ describe('ci-missing-typescript-deps', () => {
await
next
.
destroy
()
await
next
.
destroy
()
}
}
})
})
it
(
'should not throw an error if beta version of @types/react and @types/react-dom is installed'
,
async
()
=>
{
const
next
=
await
createNext
({
files
:
{
'pages/index.tsx'
:
`
export default function Page() {
return <p>hello world</p>
}
`
,
},
env
:
{
CI
:
'1'
,
},
skipStart
:
true
,
dependencies
:
{
'@types/react'
:
'npm:types-react@beta'
,
'@types/react-dom'
:
'npm:types-react-dom@beta'
,
},
packageJson
:
{
overrides
:
{
'@types/react'
:
'npm:types-react@beta'
,
'@types/react-dom'
:
'npm:types-react-dom@beta'
,
},
pnpm
:
{
overrides
:
{
'@types/react'
:
'npm:types-react@beta'
,
'@types/react-dom'
:
'npm:types-react-dom@beta'
,
},
},
},
})
try
{
const
nextBuild
=
await
next
.
build
()
// build doesn't fail because types/ may not be installed.
expect
(
nextBuild
.
cliOutput
.
split
(
'
\
n'
)).
toEqual
(
expect
.
arrayContaining
([
'This may be a bug in Next.js. Please file an issue.'
,
'Make sure the following type packages are installed:'
,
// In cyan color but this changes between CI and local.
// TODO: Use picocolors in tests to ensure we can test local and CI.
expect
.
stringContaining
(
'@types/react'
),
])
)
}
finally
{
await
next
.
destroy
()
}
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment