Skip to content

[monorepo] Formatting (prettier) fails when root package doesn't include a plugin in a nested project #4238

@devgeniussoftwarenet-hash

Description

Formatting (prettier) fails when root package doesn't include a plugin in a nested project (//package.json)

Current Behavior

Next code fails

pnpm exec lerna version --no-commit-hooks -y

with error

lerna info auto-confirmed 
lerna info execute Skipping releases
lerna ERR! Error: Cannot find package 'prettier-plugin-tailwindcss' imported from /<projectPath>/noop.js

Expected Behavior

Should work as expected

Steps to Reproduce

  1. Create a monorepo with pnpm
  2. Create a frontend folder
  3. In frontend folder install prettier@3.6.2 and any prettier plugin like prettier-plugin-tailwindcss
  4. In root install prettier@3.6.2
  5. In root install & init lerna, do some changes to make lerna version work
  6. Run pnpm exec lerna version --no-commit-hooks -y

Steps to Resolve the issue

In file

const fileInfo = await resolvedPrettier.getFileInfo(fullFilePath, { ignorePath });
change

const fileInfo = await resolvedPrettier.getFileInfo(fullFilePath, { ignorePath });

to

const fileInfo = await resolvedPrettier.getFileInfo(fullFilePath, { ignorePath, resolveConfig: false });

Why it works: with option resolveConfig: false prettier doesn't resolve the config and only checks if it is ignored or not (you do not use entire config). So in this case prettier will not try to load non existing plugin from the root and just return the needed information

Failure Logs / Configuration

Error already provided

Environment

lerna notice cli v9.0.0
lerna info versioning independent

 Environment info:

  System:
    OS: Linux 6.6 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
    CPU: (8) x64 AMD Ryzen 7 5800HS with Radeon Graphics
  Binaries:
    Node: 22.20.0 - ~/.local/share/pnpm/node
    npm: 10.9.3 - ~/.local/share/pnpm/npm
  Utilities:
    Git: 2.51.0 - /usr/bin/git
  npmPackages:
    lerna: 9.0.0 => 9.0.0 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions