I am trying to use Webpack to bundle some code that runs the Prettier API to beautify code programmatically.
I have successfully bundled and ran Prettier with one of Prettier's built-in plugins. Using a config of :
module.exports = {
entry: './index.js',
};
I was able to run the resulting ./dist/main.js file using node.
Now I want to use the prettier-plugin-java plugin with Prettier. The problem is that when I import "prettier-plugin-java" into my index.js, run npx bundle, and then try to run the resulting file, I get this error:
TypeError: Cannot read properties of null (reading '1')
at un (./main.js:1:78927)
at t.initRecognizerEngine (./main.js:1:95278)
at new t (./main.js:1:115440)
at new t.exports (./main.js:1:131052)
at 602 (./main.js:1:129653)
at n (./main.js:1:357488)
at 2507 (./main.js:1:242476)
at n (./main.js:1:357488)
at 8402 (./main.js:1:234446)
at n (./main.js:1:357488)
I tried replacing the import statement with require "prettier-plugin-java". Then I was able to run the file without error using node from the terminal.
I expected that I would get the same result (no error) when running my bundled ./dist/main.js from the terminal. Instead I got the above error: TypeError: Cannot read properties of null (reading '1')
Versions I am using:
"prettier": "^3.2.5",
"prettier-plugin-java": "^2.5.0",
"webpack-cli": "^5.1.4"