javascript - 为什么我的 eslint 自动化返回此错误?
问题描述
我已经设置了 eslint 来检查我的两个 js 文件。当我运行 eslint ./file1.js ./file2.js 时,eslint 工作正常,但是当我尝试通过将它添加到我的 package.json 文件中来自动化它时,如下所示:
"scripts": {
"start": "node file1.js"
"pretest": "eslint .\file1.js .\file2.js"
},
并尝试在我的 CLI 中使用“npm run pretest”运行它,它会返回此错误,而不是像我直接在 CLI 中键入 eslint 命令时那样正常运行:
npm ERR! code EJSONPARSE
npm ERR! file C:\filepath\package.json
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected string in JSON at position 148 while parsing '{
npm ERR! JSON.parse "name": "progproj",
npm ERR! JSON.parse "ve'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\filepath\AppData\Roaming\npm-cache\_logs\2021-01-18T00_05_33_552Z-debug.log
解决方案
您需要小心 package.json 中的 windows 路径文件。你可以用“whatever/andever”来逃避它们
然后您的脚本可能如下所示:
"scripts": {
"start": "node file1.js",
"pretest": "eslint \".\file1.js\" \".\file2.js\""
},
或者当他们指向项目文件夹时,您可以这样做:
"scripts": {
"start": "node file1.js",
"pretest": "eslint file1.js file2.js"
},
推荐阅读
- javascript - 如何在 SAPUI5 中的表列上创建链接
- php - $this->html2pdf->writeHTML($content, isset($_GET['vuehtml'])); 在codeigniter php中第二次调用时不起作用
- c - 操作总是给我 0 结果
- amazon-web-services - AWS Lambda:找出(并禁用)自己的事件源?
- react-native - 如何压缩视频并将其发送到像whatsapp这样的firebase存储反应原生
- sql - SQL设置列与其他列的键和最大值
- mongodb - MongoDB:ISODate 上的聚合管道不起作用
- javascript - 当某些元素甚至还没有被触及时,AngularJS 表单验证转换为有效
- python - 无法为 python 安装熊猫
- azure - Azure 事件网格部署失败