Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use this with standalone Prettier API? #678

Open
nop990 opened this issue Aug 1, 2024 · 2 comments
Open

Is it possible to use this with standalone Prettier API? #678

nop990 opened this issue Aug 1, 2024 · 2 comments

Comments

@nop990
Copy link

nop990 commented Aug 1, 2024

I'm writing a web extension that uses Prism and Prettier to format code on a webpage. Since I am using standalone Prettier, I have to add the plugins to the Prettier.format() call directly. The included plugins (typescript, estree, babel, etc.) import fine with require() statements, but I cannot figure out how to do this for the prettier-java-plugin. More info/code samples on my stack-overflow post

@jtkiesel
Copy link
Contributor

As of version 2.6.0, this plugin is now an ECMAScript module, so you cannot require() it. Try using import instead. You can see an example in our own website's source here.

@nop990
Copy link
Author

nop990 commented Aug 14, 2024

That throws an error in the build (using the esmify one) with this message: Error: Can't walk dependency graph: Cannot find module 'java-parser' from 'node_modules\prettier-plugin-java\dist\parser.js'. I think I've had that before and the "solution" I found was to explicitly define the dependency paths for java-parser, chevrotain, and chevrotain-allstar in the browserify process. The error would disappear and the extension would build, but when you would call the function to format the Java code, it would just hang.

My solution for now has been running the Prettier API in a Node.js server that the web extension can call. It's not ideal, but it at least works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants