用于 VS 代码的更漂亮的代码格式化程序失败,并显示“未为扩展名“.cjs”指定加载程序”

And*_*wis 15 visual-studio-code prettier

在 VS Code 中,当我选择Format Document With...然后选择时Prettier - Code Formatter,出现以下错误:

Command 'Format Document' resulted in an error (No loader specified for extension ".cjs", so searchPlaces item ".prettierrc.cjs" is invalid)
Run Code Online (Sandbox Code Playgroud)

据我所知,这与 VS Code 中的底层 TypeScript 没有可用于.cjs文件和 Prettier 搜索的加载器有关,prettierrc.cjs但我不太清楚它们是如何组合在一起的,或者如何解决它。

有没有其他人在 VS Code 中遇到过、找到解决方法或解决了这个或类似的问题?

Dhe*_*kar 31

我尝试禁用 Prettier VS Code 扩展并再次启用它,这为我解决了问题。

积分@NikolajDamLarsen