Prettier Error resolving prettier configuration for x:\xxx.prettierrc.js 解决方法
Prettier 出现如下错误
错误 内容内联代码片
Error resolving prettier configuration for d:\map\user_package\Leaflet.FileLayer-master\.prettierrc.js
["ERROR" - 10:38:26] Invalid or unexpected token
d:\map\user_package\Leaflet.FileLayer-master\.prettierrc.js:1
(function (exports, require, module, __filename, __dirname) { ��/
SyntaxError: Invalid or unexpected token
at new Script (node:vm:100:7)
at Module.u._compile (d:\Programs\Microsoft VS Code\resources\app\out\vs\loader.js:4:1173)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1216:10)
at Module.load (node:internal/modules/cjs/loader:1035:32)
at Module._load (node:internal/modules/cjs/loader:876:12)
at Function.c._load (node:electron/js2c/asar_bundle:5:13343)
at Function.r._load (d:\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:111:14538)
at Function.b._load (d:\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:106:62507)
at Function.v._load (d:\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:106:61875)
at Module.require (node:internal/modules/cjs/loader:1059:19)
at module2.exports (c:\Users\77857\.vscode\extensions\esbenp.prettier-vscode-9.10.4\node_modules\prettier\third-party.js:83:61)
at loadJs2 (c:\Users\77857\.vscode\extensions\esbenp.prettier-vscode-9.10.4\node_modules\prettier\third-party.js:8050:22)
at Explorer.loadFileContent (c:\Users\77857\.vscode\extensions\esbenp.prettier-vscode-9.10.4\node_modules\prettier\third-party.js:8449:36)
at Explorer.createCosmiconfigResult (c:\Users\77857\.vscode\extensions\esbenp.prettier-vscode-9.10.4\node_modules\prettier\third-party.js:8453:40)
at Explorer.loadSearchPlace (c:\Users\77857\.vscode\extensions\esbenp.prettier-vscode-9.10.4\node_modules\prettier\third-party.js:8438:35)
at Explorer.searchDirectory (c:\Users\77857\.vscode\extensions\esbenp.prettier-vscode-9.10.4\node_modules\prettier\third-party.js:8428:31)
at run (c:\Users\77857\.vscode\extensions\esbenp.prettier-vscode-9.10.4\node_modules\prettier\third-party.js:8413:26)
at Explorer.search (c:\Users\77857\.vscode\extensions\esbenp.prettier-vscode-9.10.4\node_modules\prettier\third-party.js:8407:24)
at Object.resolveConfigFile (c:\Users\77857\.vscode\extensions\esbenp.prettier-vscode-9.10.4\node_modules\prettier\index.js:18280:22)
at t.ModuleResolver.getResolvedConfig (c:\Users\77857\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js:1:5402)
at t.default.format (c:\Users\77857\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js:1:13308)
at t.PrettierEditProvider.provideEdits (c:\Users\77857\.vscode\extensions\esbenp.prettier-vscode-9.10.4\dist\extension.js:1:11417)
at $.provideDocumentFormattingEdits (d:\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:87:45865)
错误提示为:Invalid or unexpected token(无效或意外令牌)
这个错误提示笔者找了好半天,goole 百度都没有找到解决办法,在无果的情况下笔者开始冷静分析的原因在那,在给出的错误中提到了是.prettierrc.js配置错误,于是仔细检查并没有发现错误。
错误原因
笔者是通可命令行新建的文件新建命令如下:
PS D:\map\user_package\Leaflet.FileLayer-master> echo ‘// prettier seting file’ > .prettierrc.js
新建的文件格式笔者忘记了是UTF-16
如图所示:
解决错误
1、点击状态栏UTF-16弹出对话框
- 选择:通过编码保存如上图
2、选择UTF-8如下图所示
3、如下所示问题解决vs-code输出框信息可以正常输入
["INFO" - 11:18:13] Formatting completed in 38ms.
["INFO" - 11:18:26] Formatting file:///d%3A/map/user_package/Leaflet.FileLayer-master/.prettierrc.js
["INFO" - 11:18:26] Using config file at 'd:\map\user_package\Leaflet.FileLayer-master\.prettierrc.js'
["INFO" - 11:18:26] Using ignore file (if present) at d:\map\user_package\Leaflet.FileLayer-master\.prettierignore
["INFO" - 11:18:26] File Info:
{
"ignored": false,
"inferredParser": "babel"
}
["INFO" - 11:18:26] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 11:18:26] Prettier Options:
{
"filepath": "d:\\map\\user_package\\Leaflet.FileLayer-master\\.prettierrc.js",
"parser": "babel",
"printWidth": 150,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": true,
"bracketSpacing": true,
"jsxBracketSameLine": true,
"arrowParens": "always",
"requirePragma": false,
"insertPragma": false,
"proseWrap": "preserve",
"htmlWhitespaceSensitivity": "ignore",
"endOfLine": "lf",
"embeddedLanguageFormatting": "auto",
"spaced-comment": 0
}
["INFO" - 11:18:26] Formatting completed in 15ms.