HubSpot / prettier-maven-plugin

Apache License 2.0
116 stars 23 forks source link

Cannot find Module 'bin-prettier.js' #91

Closed Hypercookie closed 10 months ago

Hypercookie commented 1 year ago

Hi, I added this maven plugin to my multi module configuration today, and somehow it worked exactly once. From there on the only output I get is

[DEBUG] Loading mojo com.hubspot.maven.plugins:prettier-maven-plugin:0.19:check from plugin realm ClassRealm[plugin>com.hubspot.maven.plugins:prettier-maven-plugin:0.19, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@7e32c033]
[DEBUG] Configuring mojo execution 'com.hubspot.maven.plugins:prettier-maven-plugin:0.19:check:default-cli' with basic configurator -->
[DEBUG]   (f) diffGeneratorType = com.hubspot.maven.plugins.prettier.diff.DefaultDiffGenerator
[DEBUG]   (f) disableGenericsLinebreaks = false
[DEBUG]   (f) extractPrettierToTargetDirectory = false
[DEBUG]   (f) fail = true
[DEBUG]   (f) generateDiff = false
[DEBUG]   (f) ignoreConfigFile = false
[DEBUG]   (f) ignoreEditorConfig = false
[DEBUG]   (f) inputGlobs = [**/*.java, **/*.java]
[DEBUG]   (f) localRepository = /Users/<user>/.m2/repository
[DEBUG]   (f) nodeVersion = 16.13.2
[DEBUG]   (f) prettierJavaVersion = 2.2.0
[DEBUG]   (f) project = MavenProject: org.mueller:Skyline:1.0-SNAPSHOT @ <pom>
[DEBUG]   (f) skip = false
[DEBUG]   (f) pluginDescriptor = Component Descriptor: role: 'org.apache.maven.plugin.Mojo', implementation: 'com.hubspot.maven.plugins.prettier.CheckMojo', role hint: 'com.hubspot.maven.plugins:prettier-maven-plugin:0.19:check'
role: 'org.apache.maven.plugin.Mojo', implementation: 'com.hubspot.maven.plugins.prettier.PrintArgsMojo', role hint: 'com.hubspot.maven.plugins:prettier-maven-plugin:0.19:print-args'
role: 'org.apache.maven.plugin.Mojo', implementation: 'com.hubspot.maven.plugins.prettier.WriteMojo', role hint: 'com.hubspot.maven.plugins:prettier-maven-plugin:0.19:write'
---
[DEBUG] -- end configuration --
[DEBUG] Determined os: MAC_X64
[DEBUG] Reusing cached node at: /Users/<user>/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.19/node-v16.13.2-darwin-x64
[DEBUG] Reusing cached prettier-java at: /Users/<user>/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.19/prettier-java-2.2.0
[DEBUG] Running prettier with args: /Users/<user>/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.19/node-v16.13.2-darwin-x64/bin/node /Users/<user>/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.19/prettier-java-2.2.0/node_modules/prettier/bin-prettier.js --plugin=/Users/<user>/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.19/prettier-java-2.2.0/node_modules/prettier-plugin-java --color --check **/*.java **/*.java
[DEBUG] Prettier output >node:internal/modules/cjs/loader:936
[DEBUG] Prettier output >  throw err;
[DEBUG] Prettier output >  ^
[DEBUG] Prettier output >
[DEBUG] Prettier output >Error: Cannot find module '/Users/jannes/.m2/repository/com/hubspot/maven/plugins/prettier-maven-plugin/0.19/prettier-java-2.2.0/node_modules/prettier/bin-prettier.js'
[DEBUG] Prettier output >    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
[DEBUG] Prettier output >    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
[DEBUG] Prettier output >(node:internal/modules/run_main:81:12)
[DEBUG] Prettier output >    at node:internal/main/run_main_module:17:47 {
[DEBUG] Prettier output >  code: 'MODULE_NOT_FOUND',
[DEBUG] Prettier output >  requireStack: []
[DEBUG] Prettier output >}
[DEBUG] Prettier exit code: 1

I checked the paths in question and it seems like bin-prettier.js is indeed missing. I run this on a mac, but my ci pipeline runs on linux and it fails in the same way.

Thanks!

Hypercookie commented 1 year ago

One could think about replacing some of the node install part of this plugin with something that is not that permanent. For example the following command should provide a environment with prettier and prettier-java installed. It uses tea as a temporary package manager, which will remove itself and the packages after the command is run. This has the disadvantage that nothing is cached.

sh <(curl https://tea.xyz) +classic.yarnpkg.com yarn add prettier prettier-plugin-java --dev && yarn prettier <prettier-commands>
utarwyn commented 11 months ago

Hello! It seems to be an issue with prettier-java v2.2.0 which is using Prettier v3: https://github.com/jhipster/prettier-java/releases/tag/prettier-plugin-java%402.2.0

To avoid the issue, we cannot use a more recent version of prettier-java than 2.1.0.

@jhaber Is Prettier v3 support planned?

jhaber commented 10 months ago

Should be fixed by #94 which was released as part of version 0.21 just now