jscheid / prettier.el

Prettier code formatting for Emacs.
GNU General Public License v3.0
168 stars 12 forks source link

Prettier errors when using @trivago/prettier-plugin-sort-imports module #128

Closed olegat closed 1 year ago

olegat commented 1 year ago

Describe the bug prettier.el fails to format the buffer when using the @trivago/prettier-plugin-sort-imports module.

Link to M-x prettier-info output https://gist.github.com/olegat/cd11f5b552e240942b5bcae97648f9de

To Reproduce

  1. Clone https://github.com/ag-grid/ag-charts
  2. Follow the DEVELOPING.md prerequisite steps
    1. Go to root of ag-charts project cd /path/to/cloned/ag-charts
    2. Install Yarn and Nx: npm i -g yarn nx
    3. Install all dependencies: yarn install
  3. Open any typescript source file (e.g. packages/ag-charts-community/src/chart/series/cartesian/bubbleSeries.ts) in Emacs
  4. Edit the buffer (e.g. add additional whitespace in the first line)
  5. Run M-x prettier-prettify

Expected behavior The buffer should be formatted without errors.

Actual behavior prettier.el fails to format the buffer with the following error output to *prettier errors*:

/path/to/cloned/ag-charts/packages/ag-charts-community/src/chart/series/cartesian/bubbleSeries.ts: TypeError: l.resolveConfig.sync is not a function

Additional context

ikapo commented 1 year ago

I believe this is related to this issue, when I used the branch in the PR it fixed this issue for me

olegat commented 1 year ago

Could be. My project uses prettier 3:

./node_modules/prettier/bin/prettier.cjs --version
3.0.3

I will try with that branch. Thanks for the guidance.

olegat commented 1 year ago

I've tried building that branch, but it looks like one of the required node modules doesn't support Apple M2 processors.

% make
cp COPYING dist/COPYING
cp node_modules/diff-match-patch/LICENSE dist/COPYING-diff-match-patch
emacs -batch --load=./build-tools/create-pkg-el.el --eval='(prettier--create-pkg-el "dist/prettier-pkg.el")'
cp prettier.el dist/prettier.el
node_modules/.bin/google-closure-compiler \
        --js_output_file=build/prettier-el-min.js \
        --module_resolution=NODE \
        --process_common_js_modules \
        --compilation_level=ADVANCED_OPTIMIZATIONS \
        --js \
        prettier-el.js \
        node_modules/diff-match-patch/index.js \
        --externs externs.js \
        --hide_warnings_for=node_modules/diff-match-patch \
        --dependency_mode=NONE
prettier-el.js:445 (JSC_TYPE_MISMATCH)
array destructuring rhs must be Iterable
found   : module$node_modules$diff_match_patch$index.default.Diff
required: Iterable
        const [kind, str] = diffResult[index];
              ^

node -e "const fs = require('fs'); const zopfli = require('node-zopfli-es'); fs.createReadStream('build/prettier-el-min.js').pipe(zopfli.createGzip()).pipe(process.stdout)" \
        | base64 --wrap=70 > dist/prettier-el.js.gz.base64
base64: invalid argument --wrap=70
Usage:  base64 [-hDd] [-b num] [-i in_file] [-o out_file]
  -h, --help     display this message
  -Dd, --decode   decodes input
  -b, --break    break encoded string into num character lines
  -i, --input    input file (default: "-" for stdin)
  -o, --output   output file (default: "-" for stdout)
node:internal/modules/cjs/loader:1340
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: dlopen(/Users/olegat/github.com/asbish/prettier.el/node_modules/node-zopfli-es/lib/binding/zopfli.node, 0x0001): tried: '/Users/olegat/github.com/asbish/prettier.el/node_modules/node-zopfli-es/lib/binding/zopfli.node' (not a mach-o file), '/System/Volumes/Preboot/Cryptexes/OS/Users/olegat/github.com/asbish/prettier.el/node_modules/node-zopfli-es/lib/binding/zopfli.node' (no such file), '/Users/olegat/github.com/asbish/prettier.el/node_modules/node-zopfli-es/lib/binding/zopfli.node' (not a mach-o file)
    at Module._extensions..node (node:internal/modules/cjs/loader:1340:18)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:121:18)
    at Object.<anonymous> (/Users/olegat/github.com/asbish/prettier.el/node_modules/node-zopfli-es/lib/zopfli.js:5:16)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12) {
  code: 'ERR_DLOPEN_FAILED'
}

Node.js v18.17.1
make: *** [dist/prettier-el.js.gz.base64] Error 64

It might be simpler for me to watch PR #124 and try again once it's merged and released.

asbish commented 1 year ago

@olegat Could you try to installing from a pre-built package? https://github.com/jscheid/prettier.el/blob/master/RELEASING.md#installing-prs Also you can find the artifact prettier-1.3.0.178snapshot.tar here: https://github.com/jscheid/prettier.el/actions/runs/5646979357

olegat commented 1 year ago

Works like a charm! Thanks a lot of the help.