这是indexloc提供的服务,不要输入任何密码
Skip to content

turbo-ignore: fails with an unfriendly error if the monorepo root package.json does not have the name field #1859

@smorimoto

Description

@smorimoto

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.

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.

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions