Unverified Commit eabcc9ef authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

fix: display multiple lockfile warn if neither `outputFileTracingRoot` or…

fix: display multiple lockfile warn if neither `outputFileTracingRoot` or `turbopack.root` option is provided (#82164)

> Better to be reviewed with "Hide whitespace".

This PR fixed a bug where `findRootDir()` was called and displayed
multiple lockfile warnings even if the app had `turbopack.root`, as
there was no `outputFileTracingRoot`.

x-ref:
https://github.com/vercel/next.js/pull/82164#discussion_r2240470772

Also, added information about the `outputFileTracingRoot` option and its
docs to the warning, as it was omitted from
https://github.com/vercel/next.js/pull/82052.

Closes https://github.com/vercel/next.js/issues/81864
Closes https://github.com/vercel/next.js/issues/82096
parent 0899283a
...@@ -40,14 +40,25 @@ export function findRootDir(cwd: string) { ...@@ -40,14 +40,25 @@ export function findRootDir(cwd: string) {
.map((str) => '\n * ' + str) .map((str) => '\n * ' + str)
.join('') .join('')
Log.warnOnce( if (process.env.TURBOPACK) {
`Warning: Next.js inferred your workspace root, but it may not be correct.\n` + Log.warnOnce(
` We detected multiple lockfiles and selected ${lockFiles[lockFiles.length - 1]} as the root directory.\n` + `Warning: Next.js inferred your workspace root, but it may not be correct.\n` +
` To silence this warning, set turbopack.root in your Next.js config, or consider ` + ` We detected multiple lockfiles and selected the directory of ${lockFiles[lockFiles.length - 1]} as the root directory.\n` +
`removing one of the lockfiles if it's not needed.\n` + ` To silence this warning, set \`turbopack.root\` in your Next.js config, or consider ` +
` See https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#root-directory for more information.\n` + `removing one of the lockfiles if it's not needed.\n` +
` Detected additional lockfiles: ${additionalLockFiles}\n` ` See https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#root-directory for more information.\n` +
) ` Detected additional lockfiles: ${additionalLockFiles}\n`
)
} else {
Log.warnOnce(
`Warning: Next.js inferred your workspace root, but it may not be correct.\n` +
` We detected multiple lockfiles and selected the directory of ${lockFiles[lockFiles.length - 1]} as the root directory.\n` +
` To silence this warning, set \`outputFileTracingRoot\` in your Next.js config, or consider ` +
`removing one of the lockfiles if it's not needed.\n` +
` See https://nextjs.org/docs/app/api-reference/config/next-config-js/output#caveats for more information.\n` +
` Detected additional lockfiles: ${additionalLockFiles}\n`
)
}
} }
return dirname(lockFile) return dirname(lockFile)
......
...@@ -711,17 +711,12 @@ function assignDefaults( ...@@ -711,17 +711,12 @@ function assignDefaults(
} }
// use the highest level lockfile as tracing root // use the highest level lockfile as tracing root
if (!result?.outputFileTracingRoot || !result?.turbopack?.root) { if (!result?.outputFileTracingRoot && !result?.turbopack?.root) {
let rootDir = findRootDir(dir) let rootDir = findRootDir(dir)
if (rootDir) { if (rootDir) {
if (!result?.outputFileTracingRoot) { result.outputFileTracingRoot = rootDir
result.outputFileTracingRoot = rootDir dset(result, ['turbopack', 'root'], rootDir)
}
if (!result?.turbopack?.root) {
dset(result, ['turbopack', 'root'], rootDir)
}
} }
} }
......
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>hello world</p>
}
import { join } from 'path'
import { unlink } from 'fs/promises'
import { FileRef, nextTestSetup } from 'e2e-utils'
describe('multiple-lockfiles - has-output-file-tracing-root', () => {
const { next, skipped } = nextTestSetup({
files: {
app: new FileRef(join(__dirname, 'app')),
// This will silence the multiple lockfiles warning.
'next.config.js': `module.exports = { outputFileTracingRoot: __dirname }`,
// Write a package-lock.json file to the parent directory to simulate
// multiple lockfiles.
'../package-lock.json': JSON.stringify({
name: 'parent-workspace',
version: '1.0.0',
lockfileVersion: 3,
}),
},
skipDeployment: true,
})
if (skipped) {
return
}
afterAll(async () => {
// Cleanup to ensure it doesn't affect other tests.
await unlink(join(next.testDir, '../package-lock.json'))
})
it('should not have multiple lockfiles warnings', async () => {
expect(next.cliOutput).not.toMatch(
/We detected multiple lockfiles and selected the directory of .+ as the root directory\./
)
})
})
import { join } from 'path'
import { unlink } from 'fs/promises'
import { FileRef, nextTestSetup } from 'e2e-utils'
describe('multiple-lockfiles - has-turbo-root', () => {
const { next, skipped } = nextTestSetup({
files: {
app: new FileRef(join(__dirname, 'app')),
// This will silence the multiple lockfiles warning.
'next.config.js': `module.exports = { turbopack: { root: __dirname } }`,
// Write a package-lock.json file to the parent directory to simulate
// multiple lockfiles.
'../package-lock.json': JSON.stringify({
name: 'parent-workspace',
version: '1.0.0',
lockfileVersion: 3,
}),
},
skipDeployment: true,
})
if (skipped) {
return
}
afterAll(async () => {
// Cleanup to ensure it doesn't affect other tests.
await unlink(join(next.testDir, '../package-lock.json'))
})
it('should not have multiple lockfiles warnings', async () => {
expect(next.cliOutput).not.toMatch(
/We detected multiple lockfiles and selected the directory of .+ as the root directory\./
)
})
})
import { join } from 'path'
import { unlink } from 'fs/promises'
import { FileRef, nextTestSetup } from 'e2e-utils'
describe('multiple-lockfiles', () => {
const { next, skipped, isTurbopack } = nextTestSetup({
files: {
app: new FileRef(join(__dirname, 'app')),
// Write a package-lock.json file to the parent directory to simulate
// multiple lockfiles.
'../package-lock.json': JSON.stringify({
name: 'parent-workspace',
version: '1.0.0',
lockfileVersion: 3,
}),
},
skipDeployment: true,
})
if (skipped) {
return
}
afterAll(async () => {
// Cleanup to ensure it doesn't affect other tests.
await unlink(join(next.testDir, '../package-lock.json'))
})
it('should have multiple lockfiles warnings', async () => {
expect(next.cliOutput).toMatch(
/We detected multiple lockfiles and selected the directory of .+ as the root directory\./
)
if (isTurbopack) {
expect(next.cliOutput).toMatch(
/To silence this warning, set `turbopack\.root` in your Next\.js config, or consider removing one of the lockfiles if it's not needed\./
)
} else {
expect(next.cliOutput).toMatch(
/To silence this warning, set `outputFileTracingRoot` in your Next\.js config, or consider removing one of the lockfiles if it's not needed\./
)
}
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment