MCPcopy
hub / github.com/vercel/next.js / loadConfig

Function loadConfig

packages/next/src/server/config.ts:1543–1910  ·  view source on GitHub ↗
(
  phase: PHASE_TYPE,
  dir: string,
  {
    customConfig,
    rawConfig,
    silent = true,
    reportExperimentalFeatures,
    reactProductionProfiling,
    debugPrerender,
    bundler,
  }: LoadConfigOptions = {}
)

Source from the content-addressed store, hash-verified

1541): Promise<NextConfigComplete>
1542
1543export default async function loadConfig(
1544 phase: PHASE_TYPE,
1545 dir: string,
1546 {
1547 customConfig,
1548 rawConfig,
1549 silent = true,
1550 reportExperimentalFeatures,
1551 reactProductionProfiling,
1552 debugPrerender,
1553 bundler,
1554 }: LoadConfigOptions = {}
1555): Promise<NextConfigComplete> {
1556 // Generate cache key based on parameters that affect config output
1557 // Include process.pid to invalidate cache on server restart
1558 const cacheKey = getCacheKey(
1559 phase,
1560 dir,
1561 customConfig,
1562 reactProductionProfiling,
1563 debugPrerender,
1564 process.pid
1565 )
1566
1567 // Check if we have a cached result
1568 const cachedResult = configCache.get(cacheKey)
1569 if (cachedResult) {
1570 // Call the experimental features callback if provided
1571 if (reportExperimentalFeatures) {
1572 reportExperimentalFeatures(cachedResult.configuredExperimentalFeatures)
1573 }
1574
1575 // Return raw config if requested and available
1576 if (rawConfig && cachedResult.rawConfig) {
1577 return cachedResult.rawConfig
1578 }
1579
1580 return cachedResult.config
1581 } else {
1582 // Reset next.config errors before loading config
1583 // This happens on every config load to ensure fresh validation
1584 NextInstanceErrorState.nextConfig = []
1585 }
1586
1587 // Original implementation continues below...
1588 if (!process.env.__NEXT_PRIVATE_RENDER_WORKER) {
1589 try {
1590 loadWebpackHook()
1591 } catch (err) {
1592 // this can fail in standalone mode as the files
1593 // aren't traced/included
1594 if (!process.env.__NEXT_PRIVATE_STANDALONE_CONFIG) {
1595 throw err
1596 }
1597 }
1598 }
1599
1600 if (process.env.__NEXT_PRIVATE_STANDALONE_CONFIG) {

Callers 9

[SYMBOL_LOAD_CONFIG]Method · 0.70
config.test.tsFile · 0.70
webpackFinalFunction · 0.50
detached-flush.tsFile · 0.50
validateTurboNextConfigFunction · 0.50
initializeFunction · 0.50
exportAppImplFunction · 0.50
config.test.tsFile · 0.50

Calls 15

loadWebpackHookFunction · 0.90
loadEnvConfigFunction · 0.90
updateInitialEnvFunction · 0.90
normalizeConfigFunction · 0.90
interopDefaultFunction · 0.90
getCacheKeyFunction · 0.85
checkDeprecationsFunction · 0.85
applyModifyConfigFunction · 0.85
basenameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…