-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
What version of Turborepo are you using?
1.4.5
What package manager are you using / does the bug impact?
npm, pnpm, Yarn v1, Yarn v2/v3 (node_modules linker only)
What operating system are you using?
Mac
Describe the Bug
turbo-ignore
fails with an unfriendly error if the monorepo root package.json
does not have the name
field.
I believe that in most projects it would probably never be a problem, but my team didn't put the name
field in the root and tried to debug it by poking turbo-ignore
a lot, but it just didn't work, so I figured it out by going to the source.
The reason for this is that the scope
field returned by getScopeFromPath
in turbo-utils
, which turbo-ignore
uses, depends on the name
field in package.json
.
const { context, scope } = argsScope.scope ? argsScope : pathScope; |
If the scope
of argsScope
is not found, it will fallback to pathScope
, but unfortunately in this situation the scope
of pathScope
is also null
. The possible error in this case is almost always the missing name
field, and in my opinion just a polite error message is fine.
turborepo/packages/turbo-utils/src/getScopeFromPath.ts
Lines 6 to 13 in 1116799
const packageJsonPath = path.join(cwd, "package.json"); | |
try { | |
const raw = fs.readFileSync(packageJsonPath, "utf8"); | |
const packageJsonContent: Record<string, string> & { name: string } = | |
JSON.parse(raw); | |
return { | |
scope: packageJsonContent.name, |
I think it makes sense to just make sure that argsScope.scope
and scope
aren't found here, and then give a hint for users.
turborepo/packages/turbo-ignore/src/index.ts
Lines 24 to 30 in 04b077a
if (!scope) { | |
console.error( | |
"Error: app scope not found. turbo-ignore inferencing failed, proceeding with build." | |
); | |
console.error(""); | |
process.exit(1); | |
} |
Expected Behavior
It needs printing a more friendly error or different utility implementations.
To Reproduce
Remove the name
field from package.json
in the root of your current turborepo monorepo.