Skip to content

Global formatter on macOS - cannot find package 'prettier-plugin-java' #630

@Maxeh

Description

@Maxeh

Hello, I followed the readme and tried to configure the prettier plugin globally. For this I installed prettier and prettier-plugin-javaglobally with npm -g and added the file prettierrc.yaml to the root directory with the following content as described in the readme:

plugins:
  - prettier-plugin-java

When I run prettier --write "**/*.java" in the root directory I see the following error:
[error] Cannot find package 'prettier-plugin-java' imported from /Users/currentuser/projectroot/noop.js

It seems that it tries to load the plugin from the project directory and not from the global node_modules which is quite annoying. As others do not seem to have this kind of issue, this might only occur on macOS ?

When changing the plugin path in the prettierrc.yaml to an absolute path it works as expected:

plugins:
  - "/Users/currentuser/.nvm/versions/node/v18.16.1/lib/node_modules/prettier-plugin-java/dist/index.js"

However, this means that the file cannot be checked into Git and every developer has to configure the file since everyone has different paths; I cannot even replace /Users/currentuser with ~ , this also throws the same error.

Do you know how I can make it work on macOS so that I can only use the short version and do not need the absolute path? If there is no way to make it work, the documentation of this project should be adjusted and this issue must be described in the readme. It took me way too long to figure out how to get rid of the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions