1

我已经使用 vscode prettier 几个月了。我总是用它来使用 vscode 快捷方式自动格式化我的代码Shift + Alt + F>Format Document在命令面板中输入

但是突然之间,vscode 给了我这个错误这个错误消息:“invalid prettier configuration file detected. See log for details.”。这发生在将 vscode 更新到 v1.53 之后

当我单击“显示日志”时。它告诉我这个:。(原因要长得多,但我认为这是最重要的部分)

["ERROR" - 2:50:11 PM] Invalid prettier configuration file detected.
["ERROR" - 2:50:11 PM] Must use import to load ES Module: /home/koonfoon/git-repos/koonfoon/someRepo/.prettierrc.js
require() of ES modules is not supported.
require() of /home/koonfoon/git-repos/koonfoon/someRepo/.prettierrc.js from /home/koonfoon/.vscode-server/extensions/esbenp.prettier-vscode-5.9.1/node_modules/prettier/third-party.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename .prettierrc.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/koonfoon/git-repos/koonfoon/someRepo/package.json.

在我的 package.json 里面有 value "type": "module"

这就是我的 .prettierrc.js 的样子:

// .prettierrc.js

module.exports = {

    semi: true,
    trailingComma: "all",
    singleQuote: true,
    printWidth: 120,
    tabWidth: 4
    
};

.eslintrc.js:

// .eslintrc.js

module.exports = {
    "env": {
        "commonjs": true,
        "es2021": true,
        "node": true
    },
    "extends": [
        //"eslint:recommended",
        "plugin:@typescript-eslint/recommended",
        "prettier/@typescript-eslint",
        "plugin:prettier/recommended"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "rules": {
    }
};

请注意:在 vscode 更新到 v1.53 之前它工作正常

我的回购是用打字稿写的。我没有理想的原因是什么导致了这个错误。请帮忙。谢谢你。

4

0 回答 0