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
2bf8a244
Unverified
Commit
2bf8a244
authored
Jan 17, 2026
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Jan 17, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[cna] Ensure created app is not considered the workspace root in pnpm (#88647)
parent
09296125
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
127 additions
and
18 deletions
+127
-18
get-pkg-manager.ts
packages/create-next-app/helpers/get-pkg-manager.ts
+34
-0
index.ts
packages/create-next-app/templates/index.ts
+24
-18
pnpm.test.ts
.../integration/create-next-app/package-manager/pnpm.test.ts
+69
-0
No files found.
packages/create-next-app/helpers/get-pkg-manager.ts
View file @
2bf8a244
import
{
execSync
}
from
'child_process'
export
type
PackageManager
=
'npm'
|
'pnpm'
|
'yarn'
|
'bun'
export
type
PackageManager
=
'npm'
|
'pnpm'
|
'yarn'
|
'bun'
export
function
getPkgManager
():
PackageManager
{
export
function
getPkgManager
():
PackageManager
{
...
@@ -17,3 +19,35 @@ export function getPkgManager(): PackageManager {
...
@@ -17,3 +19,35 @@ export function getPkgManager(): PackageManager {
return
'npm'
return
'npm'
}
}
/**
* Get the major version of pnpm being used.
* Returns null if unable to determine the version.
*
* First tries to parse from npm_config_user_agent (e.g., "pnpm/9.13.2 npm/? ..."),
* then falls back to spawning `pnpm --version --silent`.
*/
export
function
getPnpmMajorVersion
():
number
|
null
{
// Try to get version from user agent first (e.g., "pnpm/9.13.2 npm/? node/v20.x linux x64")
const
userAgent
=
process
.
env
.
npm_config_user_agent
||
''
const
pnpmVersionMatch
=
userAgent
.
match
(
/pnpm
\/(\d
+
)
/
)
if
(
pnpmVersionMatch
)
{
return
parseInt
(
pnpmVersionMatch
[
1
],
10
)
}
// Fall back to spawning pnpm --version
try
{
const
version
=
execSync
(
'pnpm --version --silent'
,
{
encoding
:
'utf8'
,
stdio
:
[
'pipe'
,
'pipe'
,
'ignore'
],
}).
trim
()
const
majorVersion
=
parseInt
(
version
.
split
(
'.'
)[
0
],
10
)
if
(
!
Number
.
isNaN
(
majorVersion
))
{
return
majorVersion
}
}
catch
{
// pnpm not available or failed to run
}
return
null
}
packages/create-next-app/templates/index.ts
View file @
2bf8a244
import
{
install
}
from
"../helpers/install"
;
import
{
install
}
from
"../helpers/install"
;
import
{
runTypegen
}
from
"../helpers/typegen"
;
import
{
runTypegen
}
from
"../helpers/typegen"
;
import
{
copy
}
from
"../helpers/copy"
;
import
{
copy
}
from
"../helpers/copy"
;
import
{
getPnpmMajorVersion
}
from
"../helpers/get-pkg-manager"
;
import
{
async
as
glob
}
from
"fast-glob"
;
import
{
async
as
glob
}
from
"fast-glob"
;
import
os
from
"os"
;
import
os
from
"os"
;
...
@@ -320,24 +321,29 @@ export const installTemplate = async ({
...
@@ -320,24 +321,29 @@ export const installTemplate = async ({
}
}
if
(
packageManager
===
"pnpm"
)
{
if
(
packageManager
===
"pnpm"
)
{
const
pnpmWorkspaceYaml
=
[
// Only create pnpm-workspace.yaml for pnpm v10+.
// required for v9 to avoid "packages field missing or empty", v10 doesn't need it anymore
// In v9, having a pnpm-workspace.yaml (even with packages: []) causes
// TODO: remove when v9 no longer supported
// ERR_PNPM_ADDING_TO_ROOT errors when running `pnpm add`.
"packages: []"
,
// In v10, the packages field can be omitted entirely.
// v10 setting without counterpart in v9
// If we can't determine the version, assume latest (v10+) since we already
"ignoredBuiltDependencies:"
,
// know pnpm is being used at this point.
// Sharp has prebuilt binaries for the platforms next-swc has binaries.
const
pnpmMajorVersion
=
getPnpmMajorVersion
();
// If it needs to build binaries from source, next-swc wouldn't work either.
if
(
pnpmMajorVersion
===
null
||
pnpmMajorVersion
>=
10
)
{
// See https://sharp.pixelplumbing.com/install/#:~:text=When%20using%20pnpm%2C%20add%20sharp%20to%20ignoredBuiltDependencies%20to%20silence%20warnings
const
pnpmWorkspaceYaml
=
[
" - sharp"
,
"ignoredBuiltDependencies:"
,
// Not needed for pnpm: https://github.com/unrs/unrs-resolver/issues/193#issuecomment-3295510146
// Sharp has prebuilt binaries for the platforms next-swc has binaries.
" - unrs-resolver"
,
// If it needs to build binaries from source, next-swc wouldn't work either.
""
,
// See https://sharp.pixelplumbing.com/install/#:~:text=When%20using%20pnpm%2C%20add%20sharp%20to%20ignoredBuiltDependencies%20to%20silence%20warnings
].
join
(
os
.
EOL
);
" - sharp"
,
await
fs
.
writeFile
(
// Not needed for pnpm: https://github.com/unrs/unrs-resolver/issues/193#issuecomment-3295510146
path
.
join
(
root
,
"pnpm-workspace.yaml"
),
" - unrs-resolver"
,
pnpmWorkspaceYaml
,
""
,
);
].
join
(
os
.
EOL
);
await
fs
.
writeFile
(
path
.
join
(
root
,
"pnpm-workspace.yaml"
),
pnpmWorkspaceYaml
,
);
}
}
}
if
(
packageManager
===
"bun"
)
{
if
(
packageManager
===
"bun"
)
{
...
...
test/integration/create-next-app/package-manager/pnpm.test.ts
View file @
2bf8a244
...
@@ -2,6 +2,7 @@ import {
...
@@ -2,6 +2,7 @@ import {
DEFAULT_FILES
,
DEFAULT_FILES
,
FULL_EXAMPLE_PATH
,
FULL_EXAMPLE_PATH
,
projectFilesShouldExist
,
projectFilesShouldExist
,
projectFilesShouldNotExist
,
run
,
run
,
useTempDir
,
useTempDir
,
}
from
'../utils'
}
from
'../utils'
...
@@ -86,6 +87,74 @@ describe('create-next-app with package manager pnpm', () => {
...
@@ -86,6 +87,74 @@ describe('create-next-app with package manager pnpm', () => {
})
})
})
})
// These tests use --skip-install because:
// 1. We only need to verify the workspace file is created/not created
// 2. The CI runs pnpm v9, but when testing v10 behavior, the workspace file
// created for v10 (without packages field) would fail with pnpm v9
it
(
'should create pnpm-workspace.yaml for pnpm v10+'
,
async
()
=>
{
await
useTempDir
(
async
(
cwd
)
=>
{
const
projectName
=
'pnpm-v10-workspace'
const
res
=
await
run
(
[
projectName
,
'--ts'
,
'--app'
,
'--no-turbopack'
,
'--no-linter'
,
'--no-src-dir'
,
'--no-tailwind'
,
'--no-import-alias'
,
'--no-react-compiler'
,
'--skip-install'
,
],
nextTgzFilename
,
{
cwd
,
env
:
{
npm_config_user_agent
:
'pnpm/10.0.0 npm/? node/v20.0.0'
},
}
)
expect
(
res
.
exitCode
).
toBe
(
0
)
projectFilesShouldExist
({
cwd
,
projectName
,
files
:
[
'package.json'
,
'pnpm-workspace.yaml'
],
})
})
})
it
(
'should NOT create pnpm-workspace.yaml for pnpm v9'
,
async
()
=>
{
await
useTempDir
(
async
(
cwd
)
=>
{
const
projectName
=
'pnpm-v9-no-workspace'
const
res
=
await
run
(
[
projectName
,
'--ts'
,
'--app'
,
'--no-turbopack'
,
'--no-linter'
,
'--no-src-dir'
,
'--no-tailwind'
,
'--no-import-alias'
,
'--no-react-compiler'
,
'--skip-install'
,
],
nextTgzFilename
,
{
cwd
,
env
:
{
npm_config_user_agent
:
'pnpm/9.13.2 npm/? node/v20.0.0'
},
}
)
expect
(
res
.
exitCode
).
toBe
(
0
)
projectFilesShouldNotExist
({
cwd
,
projectName
,
files
:
[
'pnpm-workspace.yaml'
],
})
})
})
it
(
'should use pnpm for --use-pnpm flag with example'
,
async
()
=>
{
it
(
'should use pnpm for --use-pnpm flag with example'
,
async
()
=>
{
await
useTempDir
(
async
(
cwd
)
=>
{
await
useTempDir
(
async
(
cwd
)
=>
{
const
projectName
=
'use-pnpm-with-example'
const
projectName
=
'use-pnpm-with-example'
...
...
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