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
92bbbb1b
Unverified
Commit
92bbbb1b
authored
Oct 17, 2025
by
Niklas Mischkulnig
Committed by
GitHub
Oct 17, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport: don't define `process.cwd()` in node_modules (#84957)
Backport
https://github.com/vercel/next.js/pull/83452
parent
f895b727
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
77 additions
and
3 deletions
+77
-3
layout.js
test/production/standalone-mode/node-modules/app/layout.js
+8
-0
page.js
test/production/standalone-mode/node-modules/app/page.js
+10
-0
static-from-app.txt
...tion/standalone-mode/node-modules/app/static-from-app.txt
+1
-0
static-from-pkg.txt
...tion/standalone-mode/node-modules/app/static-from-pkg.txt
+1
-0
index.js
test/production/standalone-mode/node-modules/foo/index.js
+6
-0
package.json
.../production/standalone-mode/node-modules/foo/package.json
+4
-0
next.config.js
test/production/standalone-mode/node-modules/next.config.js
+6
-0
node-modules.test.ts
...duction/standalone-mode/node-modules/node-modules.test.ts
+22
-0
package.json
test/production/standalone-mode/node-modules/package.json
+5
-0
mod.rs
turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs
+1
-1
well_known.rs
...ck/crates/turbopack-ecmascript/src/analyzer/well_known.rs
+5
-1
mod.rs
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
+8
-1
No files found.
test/production/standalone-mode/node-modules/app/layout.js
0 → 100644
View file @
92bbbb1b
export
default
function
Root
({
children
})
{
return
(
<
html
>
<
head
><
/head
>
<
body
>
{
children
}
<
/body
>
<
/html
>
)
}
test/production/standalone-mode/node-modules/app/page.js
0 → 100644
View file @
92bbbb1b
import
path
from
'path'
import
'foo'
const
projectDir
=
process
.
cwd
()
path
.
join
(
projectDir
,
'app'
,
'static-from-app.txt'
)
export
default
function
Page
()
{
return
'hello'
}
test/production/standalone-mode/node-modules/app/static-from-app.txt
0 → 100644
View file @
92bbbb1b
hello
test/production/standalone-mode/node-modules/app/static-from-pkg.txt
0 → 100644
View file @
92bbbb1b
hello
test/production/standalone-mode/node-modules/foo/index.js
0 → 100644
View file @
92bbbb1b
import
path
from
'path'
const
projectDir
=
process
.
cwd
()
path
.
join
(
projectDir
,
'app'
,
'static-from-pkg.txt'
)
export
default
'foo'
test/production/standalone-mode/node-modules/foo/package.json
0 → 100644
View file @
92bbbb1b
{
"name"
:
"foo"
,
"version"
:
"0.0.0"
}
test/production/standalone-mode/node-modules/next.config.js
0 → 100644
View file @
92bbbb1b
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{}
module
.
exports
=
nextConfig
test/production/standalone-mode/node-modules/node-modules.test.ts
0 → 100644
View file @
92bbbb1b
import
{
nextTestSetup
}
from
'e2e-utils'
describe
(
'standalone mode - NFT in node_modules'
,
()
=>
{
const
dependencies
=
require
(
'./package.json'
).
dependencies
const
{
next
,
skipped
}
=
nextTestSetup
({
files
:
__dirname
,
dependencies
,
skipDeployment
:
true
,
})
if
(
skipped
)
{
return
}
it
(
'should not trace process.cwd calls in node_modules'
,
async
()
=>
{
let
trace
=
await
next
.
readJSON
(
'.next/server/app/page.js.nft.json'
)
expect
(
trace
.
files
).
toContain
(
'../../../app/static-from-app.txt'
)
expect
(
trace
.
files
).
not
.
toContain
(
'../../../app/static-from-pkg.txt'
)
})
})
test/production/standalone-mode/node-modules/package.json
0 → 100644
View file @
92bbbb1b
{
"dependencies"
:
{
"foo"
:
"file:./foo"
}
}
turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs
View file @
92bbbb1b
...
...
@@ -4032,7 +4032,7 @@ pub mod test_utils {
}
}
_
=>
{
let
(
mut
v
,
m1
)
=
replace_well_known
(
v
,
compile_time_info
)
.await
?
;
let
(
mut
v
,
m1
)
=
replace_well_known
(
v
,
compile_time_info
,
true
)
.await
?
;
let
m2
=
replace_builtin
(
&
mut
v
);
let
m
=
m1
||
m2
||
v
.make_nested_operations_unknown
();
return
Ok
((
v
,
m
));
...
...
turbopack/crates/turbopack-ecmascript/src/analyzer/well_known.rs
View file @
92bbbb1b
...
...
@@ -15,6 +15,7 @@ use crate::analyzer::RequireContextValue;
pub
async
fn
replace_well_known
(
value
:
JsValue
,
compile_time_info
:
Vc
<
CompileTimeInfo
>
,
define_process_cwd
:
bool
,
)
->
Result
<
(
JsValue
,
bool
)
>
{
Ok
(
match
value
{
JsValue
::
Call
(
_
,
box
JsValue
::
WellKnownFunction
(
kind
),
args
)
=>
(
...
...
@@ -23,6 +24,7 @@ pub async fn replace_well_known(
JsValue
::
unknown_empty
(
false
,
"this is not analyzed yet"
),
args
,
compile_time_info
,
define_process_cwd
,
)
.await
?
,
true
,
...
...
@@ -52,6 +54,7 @@ pub async fn well_known_function_call(
_this
:
JsValue
,
args
:
Vec
<
JsValue
>
,
compile_time_info
:
Vc
<
CompileTimeInfo
>
,
define_process_cwd
:
bool
,
)
->
Result
<
JsValue
>
{
Ok
(
match
kind
{
WellKnownFunctionKind
::
ObjectAssign
=>
object_assign
(
args
),
...
...
@@ -85,7 +88,8 @@ pub async fn well_known_function_call(
.as_str
()
.into
(),
WellKnownFunctionKind
::
ProcessCwd
=>
{
if
let
Some
(
cwd
)
=
&*
compile_time_info
.environment
()
.cwd
()
.await
?
{
if
define_process_cwd
&&
let
Some
(
cwd
)
=
&*
compile_time_info
.environment
()
.cwd
()
.await
?
{
cwd
.clone
()
.into
()
}
else
{
JsValue
::
unknown
(
...
...
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
View file @
92bbbb1b
...
...
@@ -429,6 +429,7 @@ struct AnalysisState<'a> {
origin
:
ResolvedVc
<
Box
<
dyn
ResolveOrigin
>>
,
compile_time_info
:
ResolvedVc
<
CompileTimeInfo
>
,
var_graph
:
&
'a
VarGraph
,
define_process_cwd
:
bool
,
/// This is the current state of known values of function
/// arguments.
fun_args_values
:
Mutex
<
FxHashMap
<
u32
,
Vec
<
JsValue
>>>
,
...
...
@@ -458,6 +459,7 @@ impl AnalysisState<'_> {
&
self
.free_var_references
,
self
.var_graph
,
attributes
,
self
.define_process_cwd
,
)
},
&
self
.fun_args_values
,
...
...
@@ -988,6 +990,7 @@ pub(crate) async fn analyse_ecmascript_module_internal(
origin
,
compile_time_info
,
var_graph
:
&
var_graph
,
define_process_cwd
:
!
source
.ident
()
.path
()
.await
?
.path
.contains
(
"/node_modules/"
),
fun_args_values
:
Default
::
default
(),
var_cache
:
Default
::
default
(),
first_import_meta
:
true
,
...
...
@@ -2868,6 +2871,7 @@ async fn value_visitor(
>
,
var_graph
:
&
VarGraph
,
attributes
:
&
ImportAttributes
,
define_process_cwd
:
bool
,
)
->
Result
<
(
JsValue
,
bool
)
>
{
let
(
mut
v
,
modified
)
=
value_visitor_inner
(
origin
,
...
...
@@ -2876,6 +2880,7 @@ async fn value_visitor(
free_var_references
,
var_graph
,
attributes
,
define_process_cwd
,
)
.await
?
;
v
.normalize_shallow
();
...
...
@@ -2892,6 +2897,7 @@ async fn value_visitor_inner(
>
,
var_graph
:
&
VarGraph
,
attributes
:
&
ImportAttributes
,
define_process_cwd
:
bool
,
)
->
Result
<
(
JsValue
,
bool
)
>
{
let
ImportAttributes
{
ignore
,
..
}
=
*
attributes
;
// This check is just an optimization
...
...
@@ -3021,7 +3027,8 @@ async fn value_visitor_inner(
v
.into_unknown
(
true
,
"cross function analyzing is not yet supported"
)
}
_
=>
{
let
(
mut
v
,
mut
modified
)
=
replace_well_known
(
v
,
compile_time_info
)
.await
?
;
let
(
mut
v
,
mut
modified
)
=
replace_well_known
(
v
,
compile_time_info
,
define_process_cwd
)
.await
?
;
modified
=
replace_builtin
(
&
mut
v
)
||
modified
;
modified
=
modified
||
v
.make_nested_operations_unknown
();
return
Ok
((
v
,
modified
));
...
...
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