next.js 错误:文件“/Users/hello/Documents/projects/hello_world/.eslintrc.json”的配置无效

64jmpszr  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(103)

当我在我的nextjs项目的根目录下运行npm run format命令时,我得到了这个错误消息:

[error] Invalid configuration for file "/Users/hello/Documents/projects/hello_world/.eslintrc.json":
[error] require() of ES Module /Users/hello/Documents/projects/hello_world/node_modules/prettier-plugin-tailwindcss/dist/index.mjs not supported.
[error] Instead change the require of /Users/hello/Documents/projects/hello_world/node_modules/prettier-plugin-tailwindcss/dist/index.mjs to a dynamic import() which is available in all CommonJS modules.

.eslintrc.json文件:

{
  "extends": "next/core-web-vitals",
  "ignorePatterns": [".eslintrc.json"]
}

prettier.config.js文件:

module.exports = {
    bracketSpacing: true,
    semi: true,
    trailingComma: "all",
    printWidth: 80,
    tabWidth: 2,
    plugins: [require("prettier-plugin-tailwindcss")],
};

package.json file

{
  "name": "hello_world",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "lint": "next lint",
    "format:write": "prettier --write \"**/*.{css,js,json,jsx,ts,tsx}\"",
    "format": "prettier \"**/*.{css,js,json,jsx,ts,tsx}\""
  },
  "dependencies": {
    // some dependencies
  },
  "devDependencies": {
    "autoprefixer": "latest",
    "eslint": "latest",
    "eslint-config-next": "latest",
    "postcss": "latest",
    "prettier": "^3.0.3",
    "prettier-plugin-tailwindcss": "^0.5.4",
    "tailwindcss": "latest"
  }
}

文件/文件夹结构:

lymnna71

lymnna711#

tailwind排序插件与prettier v3.0.0不兼容。以下是如何降级:
Prettier v2.8.8:
Yarn:yarn add [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection) -D
NPM:npm install [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection) --save-dev
prettier-plugin-tailwindcss v0.4.0:
沿着降级Prettier,也有必要为Prettier降级tailwindcss插件。
Yarn:yarn add [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection) -D
NPM:npm install [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection) --save-dev
等待兼容性修复的更新。

相关问题