Error screenshot
[error] Invalid configuration file `src\index.js`: JSON Error in E:\202112\testPrettier\.prettierrc.json:
[error]
[error] > 1 | ��
[error] | ^
[error]
[error] Unexpected token "�" (0xFFFD) in JSON at position 0 while parsing "��"
[error]
[error] > 1 | ��
[error] | ^
[error]
Installation process
Install prettier
yarn add --dev --exact prettier
Create .Prettier.json
echo {}> .prettierrc.json
Create .prettierignore
echo {}> .prettierignore
# write content
src/assets
**/*.md
**/*.svg
**/*.html
**/*.ejs
**/*.png
**/*.eot
**/*.woff
**/*.ttf
**/*.gif
**/*.jpg
**/*.jpeg
package.json
Execute yarn prettier --write .
, an error will be report:
Check the index.js in prettier as following:
searchPlaces: ["package.json", ".prettierrc", ".prettierrc.json", ".prettierrc.yaml", ".prettierrc.yml", ".prettierrc.json5", ".prettierrc.js", ".prettierrc.cjs", "prettier.config.js", "prettier.config.cjs", ".prettierrc.toml"],
loaders: {
".toml": loadToml,
".json5": loadJson5
}
More than one name was found prettierrc.JSON
format file
Solution:
Replace prettier.json
file with pretierrc.config.js
file and write its internal contents in the following way:
module.exports = {
trailingComma: "es5",
tabWidth: 4,
semi: false,
singleQuote: true,
};
You can format the file. I don’t understand why.
Combined with husky, the project automatically formats the code before submitting GIT
Premise: the project must be git controlled, otherwise the following will report an error and install lint staged
npx [email protected] lint-staged
This is a relatively simple and fast way
Read More:
- [Solved] ESLint: Parsing error: Unexpected token(prettier/prettier)
- eslint Error: Delete `␍` [How to Solve]
- [Solved] Vue3 Error: error Delete `··` prettier/prettier
- Vscode save Vue format eslint check error [How to Solve]
- [Solved] Vue prettier error: error Delete `␍` prettier/prettier
- [Solved] VS Code Error: Vetur can‘t find ‘tsconfig.json‘ or ‘jsconfig.json‘
- CRA 5.0.0 Add Proxy Project Start Error [How to Solve]
- [Solved] ✖ 2 problem (1 error, 0 warnings) 2 error and 0 warnings potentially fixable with the`–fix`
- [Solved] error when starting dev server:Error: The following dependencies are imported but could not be reso
- Difference between contenttype and datatype in Ajax request of jquery
- React: How to Solve Web3 import error
- [Vue Run Error] Module build failed: Error: Couldn‘t resolve parser “babylon“
- Vue: How to Solve Eslint error
- [Solved] Error: Transform failed with 1 error: error: Invalid option in transform() call: “jsx“
- npm ERR code ELIFECYCLE [How to Solve]
- Vue-cli2 sub environment packaging
- [Solved] Vue Error: Module build failed: Error: No PostCSS Config found in
- [Solved] Syntax Error: Error: No ESLint configuration found & TypeError: eslint.CLIEngine is not a constructor
- [Solved] Install The Latest Version of Jest Error: TypeError: Cannot read property ‘instrument‘ of undefined
- How to Solve Vue-devtool Package Error