[英]Why does my eslint automation return this error?
I have set up eslint to check my two js files.我已经设置了 eslint 来检查我的两个 js 文件。 When I run eslint./file1.js./file2.js the eslint works fine however when i try to automate it by adding it to my package.json file like this:
当我运行 eslint./file1.js./file2.js 时,eslint 工作正常,但是当我尝试通过将其添加到我的 package.json 文件来自动化它时,如下所示:
"scripts": {
"start": "node file1.js"
"pretest": "eslint .\file1.js .\file2.js"
},
and try to run it by using 'npm run pretest' in my CLI it returns this error, rather than running normally like it does when I type the eslint command directly in my CLI:并尝试在我的 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
You need to be careful with windows path files in package.json.您需要小心 package.json 中的 windows 路径文件。 You can scape them with "whatever/andever"
你可以用“whatever/andever”来逃避它们
Then your script could look like:然后您的脚本可能如下所示:
"scripts": {
"start": "node file1.js",
"pretest": "eslint \".\file1.js\" \".\file2.js\""
},
Or as they point to the project folder you could do:或者当他们指向项目文件夹时,您可以这样做:
"scripts": {
"start": "node file1.js",
"pretest": "eslint file1.js file2.js"
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.