Prettier 配置文件写成.prettierrc.js不生效是什么原因?-灵析社区

周舟莫UI设计

保存格式化prettier格式化配置没有生效?.prettierrc.js没有生效,但是配置文件要是写成`.prettierrc`或者`.prettierrc.json` json格式就能被读取并生效,这是啥问题呢? 设置步骤如下 1. 添加prettier配置文件 2. formatOnSave: true 如果我prettier配置文件是json格式的,是能读到项目的prettier配置项并格式化生效 ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241014/399eac3fe60c9afb928a0f97763cf61f.png)格式化也正确 但是如果我写的是`.prettierrc.js` 时候,对应的配置项目好像没有被读取到(或者是被默认的覆盖了?) ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241014/19ddb1e1e0f38694b276af2c78bbd04d.png) 可以看到读取配置并不是`.prettierrc.js`的配置项而是全局设置的默认项。 这大概会是什么原因呢? package.json如下 { "name": "nodejs-koa2-blog", "version": "1.0.0", "description": "基于 Node.js Koa2 实战开发的一套完整的博客项目网站,使用 Koa2 二次开发一套适合多端的 RESTful API,同时配套完整的后台管理系统,且前端展示既有基于 ejs 服务端渲染,也有基于 Vue.js 前后端分离的 2 套前端网站。", "main": "index.js", "scripts": { "dev": "nodemon app.js", "test": "jest _tests --forceExit --runInBand --colors" }, "repository": { "type": "git", "url": "git+https://github.com/liangfengbo/nodejs-koa2-blog.git" }, "keywords": [ "nodejs", "koa2", "sequelize", "mysql", "ejs", "vuejs", "JavaScript", "博客网站", "Node.js实战", "ejs 服务端渲染" ], "author": "Fengbo Liang, https://github.com/lfb", "license": "ISC", "bugs": { "url": "https://github.com/lfb/nodejs-koa2-blog/issues" }, "_moduleAliases": { "@": ".", "@app": "app", "@core": "core", "@middlewares": "middlewares", "@api": "app/api", "@dao": "app/dao", "@lib": "app/lib", "@models": "app/models", "@service": "app/service", "@validators": "app/validators" }, "homepage": "https://github.com/lfb/nodejs-koa2-blog#readme", "dependencies": { "@koa/cors": "^3.0.0", "basic-auth": "^2.0.1", "bcryptjs": "^2.4.3", "ejs": "^3.1.8", "hashids": "^2.1.0", "highlight.js": "^11.1.0", "jest": "^24.9.0", "jsonwebtoken": "^8.4.0", "koa": "^2.7.0", "koa-bodyparser": "^4.2.1", "koa-ratelimit": "^5.0.1", "koa-router": "^7.4.0", "koa-static": "^5.0.0", "koa-views": "^8.0.0", "markdown-it": "^12.1.0", "module-alias": "^2.2.2", "moment": "^2.24.0", "mysql2": "^2.2.5", "nodemon": "^2.0.12", "npm-check": "^5.9.0", "qiniu": "^7.4.0", "require-directory": "^2.1.1", "sequelize": "^6.6.5", "supertest": "^4.0.2", "validator": "^10.11.0", "xss": "^1.0.6" }, "directories": { "test": "_tests" }, "devDependencies": { "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "prettier": "3.2.4" } }

阅读量:208

点赞量:0

问AI
真离谱,问题的原因大概是改了.prettier.js 配置文件需要重启一下vscode,我试了下能生效。非常离谱,但是改pretterrc.json类型修改完就能生效。