prettier-vscode icon indicating copy to clipboard operation
prettier-vscode copied to clipboard

Unable to format new syntax?

Open ajiho opened this issue 1 year ago • 7 comments

Summary

When the following code appears in the JS file, it cannot work

import navJson from "../nav.json" with { type: "json" };

Github Repository to Reproduce Issue

NOT REQUIRED

Steps To Reproduce:

NOT REQUIRED

Expected result

Can format normally

Actual result

SyntaxError: Unexpected token, expected

Additional information

image

VS Code Version:

版本: 1.95.1 (user setup)
提交: 65edc4939843c90c34d61f4ce11704f09d3e5cb6
日期: 2024-10-31T05:14:54.222Z
Electron: 32.2.1
ElectronBuildId: 10427718
Chromium: 128.0.6613.186
Node.js: 20.18.0
V8: 12.8.374.38-electron.0
OS: Windows_NT x64 10.0.19044

Prettier Extension Version:v11.0.0

OS and version:win10

Prettier Log Output

import navJson from "../nav.json" with { type: "json" };
  4 |
  5 | const config = JSON.parse(process.env.MY_ENV_CONFIGS);
SyntaxError: Unexpected token, expected "(" (2:43)
  1 | import { defineConfig } from "vitepress";
> 2 | import sidebar from "./sidebar.json" with { type: "json" };
    |                                           ^
  3 | import navJson from "../nav.json" with { type: "json" };
  4 |
  5 | const config = JSON.parse(process.env.MY_ENV_CONFIGS);
    at p (c:\Users\Administrator\.vscode\extensions\esbenp.prettier-vscode-11.0.0\node_modules\prettier\parser-babel.js:22:1054)
    at d (c:\Users\Administrator\.vscode\extensions\esbenp.prettier-vscode-11.0.0\node_modules\prettier\parser-babel.js:22:1287)
    at Object.parse (c:\Users\Administrator\.vscode\extensions\esbenp.prettier-vscode-11.0.0\node_modules\prettier\parser-babel.js:29:54501)
    at Object.parse (c:\Users\Administrator\.vscode\extensions\esbenp.prettier-vscode-11.0.0\node_modules\prettier\index.js:7515:23)
    at coreFormat (c:\Users\Administrator\.vscode\extensions\esbenp.prettier-vscode-11.0.0\node_modules\prettier\index.js:8829:18)
    at formatWithCursor2 (c:\Users\Administrator\.vscode\extensions\esbenp.prettier-vscode-11.0.0\node_modules\prettier\index.js:9021:18)
    at c:\Users\Administrator\.vscode\extensions\esbenp.prettier-vscode-11.0.0\node_modules\prettier\index.js:38183:12
    at Object.format (c:\Users\Administrator\.vscode\extensions\esbenp.prettier-vscode-11.0.0\node_modules\prettier\index.js:38197:12)
    at t.default.format (c:\Users\Administrator\.vscode\extensions\esbenp.prettier-vscode-11.0.0\dist\extension.js:1:16369)
    at t.PrettierEditProvider.provideEdits (c:\Users\Administrator\.vscode\extensions\esbenp.prettier-vscode-11.0.0\dist\extension.js:1:12927)
    at g$.provideDocumentFormattingEdits (file:///c:/Users/Administrator/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:137:134090)
["INFO" - 13:33:04] Formatting completed in 11ms.

ajiho avatar Dec 04 '24 05:12 ajiho

This issue has been labeled as stale due to inactivity. Reply to keep this issue open.

github-actions[bot] avatar Feb 03 '25 02:02 github-actions[bot]

The problem is annoying as hell and still occurs.

thevalleyy avatar Feb 03 '25 06:02 thevalleyy

Any update dear community on this? I feel the same as @thevalleyy, does anybody know how you can fix this, any workaround?

kasir-barati avatar Mar 18 '25 17:03 kasir-barati

Workaround: either local install of the latest version of prettier, or global install and enable "Resolve global modules"

vamitul avatar Mar 20 '25 14:03 vamitul

Enabling Resolve global modules didn't fix the issue

thevalleyy avatar Mar 31 '25 16:03 thevalleyy

keywords: import attributes

#3593

cluah avatar Jun 22 '25 10:06 cluah

This issue should be resolved in version 12 of the extension. Version 12 is currently in preview and is published only to the new Prettier organization. You can find that version here: https://marketplace.visualstudio.com/items?itemName=Prettier.prettier-vscode

Once we decide version 12 is stable it will be published to the old extension location as well.

Please test this issue in version 12 and let me know if this is still an issue. If we don't hear back this issue may be closed.

ntotten avatar Dec 01 '25 23:12 ntotten