当我在我的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"
}
}
文件/文件夹结构:
1条答案
按热度按时间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
等待兼容性修复的更新。