如何解决更漂亮的错误:ENOENT:没有这样的文件或目录
我只是在我现有的反应项目 (CSR) 中设置了 eslint 和 prettier 并执行了“npm run prettier”,然后我得到了如下错误。
我该如何解决这个错误? 仅供参考,存在 src/App.tsx 文件,与下面的错误不同。
> ut-admin-web@3.1.0 prettier /Users/jin/projects_new/backup/2021/ut-admin-react-test
> prettier --write --config ./.prettierrc './src/**/*.{ts,tsx}'
[error] Invalid configuration file `src/App.tsx`: ENOENT: no such file or directory,open '/.../.prettierrc'
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! ut-admin-web@3.1.0 prettier: `prettier --write --config ./.prettierrc './src/**/*.{ts,tsx}'`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the ...@3.1.0 prettier script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
我的 .prettierrc.json
{
"singleQuote": true,"parser": "typescript","semi": false,"useTabs": true,"printWidth": 120
}
我的 .eslintrc.json
{
"env": {
"browser": true,"es6": true
},"extends": [
"prettier","prettier/react","eslint:recommended","plugin:react/recommended","plugin:@typescript-eslint/eslint-recommended","airbnb","airbnb/hooks","prettier/@typescript-eslint","plugin:prettier/recommended"
],"globals": {
"Atomics": "readonly","SharedArrayBuffer": "readonly"
},"parser": "@typescript-eslint/parser","parserOptions": {
"ecmaFeatures": {
"jsx": true
},"ecmaVersion": 2018,"sourceType": "module"
},"plugins": [
"react","@typescript-eslint"
],"rules": {
}
}
最后这里是我的 package.json 的一部分
...
...
"lint": "eslint './src/**/*.{ts,tsx,js,jsx}'","lint:fix": "eslint --fix './src/**/*.{ts,"prettier": "prettier --write --config ./.prettierrc './src/**/*.{ts,tsx}'"
...
解决方法
将您更漂亮的配置移动到 package.json
中的一个键中(并删除 rc 文件):
{
"dependencies": ...,"prettier": {
"singleQuote": true,"semi": false,"useTabs": true,"printWidth": 120
}
}
并将您的 prettier
脚本简化为
"prettier": "prettier --write ./src"
你应该没事。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。